Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove 'command not found' error discord.py

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?

like image 446
Tim Birtles Avatar asked Oct 19 '18 21:10

Tim Birtles


People also ask

How do I delete discord bot py?

Use this "await ctx. message. delete()" at the top of your command, it will find the last sent message and delete it.

Is discord.py getting discontinued?

Discord py is getting discontinued because Discord implemented more and more restrictions for Bot Developers, promised easy verification steps but is behind verification processes by months. Yet introducing more restrictions and now requiring even ID copies.

How do you make commands for discord bot py?

Commands are defined by attaching it to a regular Python function. The command is then invoked by the user using a similar signature to the Python function. You must have access to the message_content intent for the commands extension to function. This must be set both in the developer portal and within your code.


2 Answers

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
like image 116
Patrick Haugh Avatar answered Sep 24 '22 12:09

Patrick Haugh


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)
like image 20
Exd Craft Avatar answered Sep 24 '22 12:09

Exd Craft