Home > other >  How to get the command name when a command not found error occurs discord.py
How to get the command name when a command not found error occurs discord.py

Time:04-20

I have made an event called on_command_error which intercepts the orginal command error. In that event it sends to the channel the command was executed in. "The command you have executed is not found". I want it to be able to say. "The command {commandname} has not been found". I don't know how to get the command name.

@bot.event
async def on_command_error(ctx, error):
    if isinstance(error, CommandNotFound):
        await ctx.send("The command you have executed is not found.")

CodePudding user response:

this may not be the best way of doing this, but a solution I discovered is:

async def on_command_error(ctx, error):
    if isinstance(error, CommandNotFound):
        await ctx.send(f"The command {error} you have executed is not found. use the command !help for a list of available commands")
  • Related