Remove 'command not found' error discord.py

14,454

Solution 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

Solution 2

You can try this, just change the title and the description inside the "em" part.

@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)
Share:
14,454
Tim Birtles
Author by

Tim Birtles

Updated on June 15, 2022

Comments

  • Tim Birtles
    Tim Birtles almost 2 years

    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?

  • Eric Aya
    Eric Aya over 2 years
    This has already been mentioned in the other answers.