Remove 'command not found' error discord.py

北战南征 提交于 2020-01-13 20:33:08

问题


In a discord.py rewrite bot, if someone types the bots prefix and then any text after it, if the text is not found as a command you will get

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

Is there anyway to stop the bot from logging this?


回答1:


Write an on_command_error error handler that checks if the error is an instance of CommandNotFound, and ignores it if it is

from discord.ext.commands import CommandNotFound

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


来源:https://stackoverflow.com/questions/52900101/remove-command-not-found-error-discord-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!