首页 > 解决方案 > 代码停止执行 Ban discord bot, 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”后,脚本停止运行

标签: pythondiscorddiscord.py

解决方案


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

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

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


推荐阅读