【发布时间】:2021-02-24 21:23:54
【问题描述】:
我尝试在用户无权使用命令时发出错误消息,这是因为我在控制台中不断收到错误消息,当用户没有权限时,代码应该在聊天中发送消息有权限使用它,错误已从控制台消失,但它没有输出消息
@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!')
【问题讨论】:
-
如果没有输出消息,说明错误不是
MissingPermissions。您能否尝试在错误处理程序中添加print(error)并告诉我们会发生什么? -
我的机器人也有完全相同的代码,但不是检查
MissingPermissions,而是检查CheckFailure,这对我来说很好。 -
我尝试将
print(error)放入我的代码并运行它,但控制台仍然显示为空白@kr8gz。我也尝试在代码中使用CheckFailure,但仍然遇到同样的问题
标签: discord.py