代码停止执行Ban discord bot,python

2024-05-15 12:24:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个密码:

@commands.has_permissions(ban_members=True)
@Client.command()
async def Ban (ctx, member:discord.User=None, reason="Nie podano"):
    if member == None or member == ctx.message.author:
        await ctx.channel.send("Nie możesz zbanować sam siebie")
        return
    message = f"Zostałeś zbanowany na serwerze {ctx.guild.name}\nPowód: {reason}"
    await member.send(message)
    await ctx.channel.purge(limit = 1)
    await ctx.channel.send(f"{member} Został zbanowany!\nPowód: {reason}")
    print('a')
    await member.ban(reason = reason)
    print('b')

所有操作都已完成,但在控制台中显示字母“a”后,脚本停止运行


Tags: nonesend密码messagechannelawaitmemberreason
2条回答

我看不出你的代码有任何问题,如果你有任何错误,请提及它们,或者如果你有错误处理程序,请尝试通过注释删除它,然后尝试获取错误

await ctx.guild.ban(member, reason=reason)

我做了很多discord.py,但从未遇到过代码停止的问题。最后(我认为这不是问题)您可能需要检查您拥有的python版本以及discord.py所需的版本

你必须检查你的机器人是否有成员意图和足够的权利来禁止成员

要添加成员意图,请执行以下操作:

intents = discord.Intents.default()
intents.members = True

在实例化bot之前,然后:

bot = commands.Bot(command_prefix='...', intents=intents)

为了更好地授予您的bot-ban权限,请通过权限将其设置为管理员

相关问题 更多 >