【发布时间】:2021-07-23 09:29:12
【问题描述】:
我有一个 Discord.py 重写机器人,它通过 on_command_error 事件向某个频道发送错误消息。
我想知道,如果该命令的custom error handler 已经处理了错误,是否有任何方法可以忽略我的on_command_error() 事件。
【问题讨论】:
标签: python error-handling discord.py
我有一个 Discord.py 重写机器人,它通过 on_command_error 事件向某个频道发送错误消息。
我想知道,如果该命令的custom error handler 已经处理了错误,是否有任何方法可以忽略我的on_command_error() 事件。
【问题讨论】:
标签: python error-handling discord.py
您应该通过commands.Command.has_error_handler() 方法检查调用的命令是否具有错误处理程序。这是一个例子:
@bot.command()
async def my_command(ctx):
raise Exception("oops")
@my_command.error
async def handle_error(ctx, error):
# handle the error
@bot.on_command_error(ctx, error):
if ctx.command.has_error_handler():
return # since it has a custom error handler, do nothing here
# if you reach this point, then there is no error handler
# and you can handle it normally.
参考资料:
【讨论】: