在不和谐中使用错误命令时,我在生成自定义错误消息时遇到了一些问题。
代码是:
@client.event
async def on_message_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.CommandNotFound):
await ctx.send("Unknown command")
如果我使用了错误的命令,控制台会出现以下内容:
<块引用>忽略命令 None 中的异常: discord.ext.commands.errors.CommandNotFound:未找到命令“错误的命令”
但不和谐机器人不会发送“未知命令”消息。
我做错了什么?
答案 0 :(得分:0)
就像 Łukasz 所说的,将您的 on_message_error
替换为 on_command_error
。您可以在 the docs here 中查看。
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound): # or discord.ext.commands.errors.CommandNotFound as you wrote
await ctx.send("Unknown command")