删除“找不到命令”错误 discord.py

新手上路,请多包涵

在 discord.py 重写机器人中,如果有人输入机器人前缀,然后输入任何文本,如果找不到该文本作为命令,您将得到

Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "sd" is not found

无论如何要阻止机器人记录这个?

原文由 Tim Birtles 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 535
2 个回答

编写一个 on_command_error 错误处理程序,检查错误是否是 CommandNotFound 的实例,如果是则忽略它

from discord.ext.commands import CommandNotFound

@bot.event
async def on_command_error(ctx, error):
    if isinstance(error, CommandNotFound):
        return
    raise error

原文由 Patrick Haugh 发布,翻译遵循 CC BY-SA 4.0 许可协议

您可以试试这个,只需更改“em”部分内的标题和描述即可。

 @client.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandNotFound):
        em = discord.Embed(title=f"Error!!!", description=f"Command not found.", color=ctx.author.color)
        await ctx.send(embed=em)

原文由 Exd Craft 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题