Discord.py错误处理未输出消息?

时间:2020-11-12 20:28:06

标签: discord.py

我试图在用户没有使用该命令的权限时发出错误消息,这是因为我一直在控制台中收到错误消息,该代码应该在用户不使用时在聊天中发送消息有权使用它,错误已从控制台中消失,但不会输出消息

@client.command()
@has_permissions(manage_messages=True)
async def clear(ctx, limit: int):
    await ctx.channel.purge(limit = limit)
    await ctx.send('Cleared by {}'.format(ctx.author.mention))

@clear.error
async def clear_error(error, ctx):
    if isinstance(error, MissingPermissions):
        await ctx.send('Sorry, you do not have permissions to do that!')

1 个答案:

答案 0 :(得分:1)

使用错误处理功能时,必须执行async def clear_error(ctx, error):。基本上,您只需要交换参数的位置即可。

@clear.error
async def clear_error(ctx, error):
    if isinstance(error, MissingPermissions):
        await ctx.send('Sorry, you do not have permissions to do that!')