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

Tim*_*les 9 python python-3.x discord discord.py discord.py-rewrite

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

Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "sd" is not found
Run Code Online (Sandbox Code Playgroud)

有没有办法阻止机器人记录这个?

Pat*_*ugh 20

编写一个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
Run Code Online (Sandbox Code Playgroud)