Rambo Dash
Rambo Dash

Reputation: 49

How do I get the name of command that raised error in discord.py?

I want my bot to make some kind of command log and I want it not only send that "some command was just executed", but also send if user raised any errors while trying to use this command (missing argument/permission and so on). I want to implement it using on_command_error(), but I still need to know which command raised the error. Is there any way of doing that?

Upvotes: 0

Views: 1222

Answers (1)

teaishealthy
teaishealthy

Reputation: 133

Because you get the ctx from the failed command, you can access the command name with ctx.invoked_with or ctx.command if you want the full command object.

...
@bot.event
async def on_command_error(ctx, error):
    command = ctx.invoked_with

See: https://discordpy.readthedocs.io/en/stable/ext/commands/api.html?highlight=notfound#discord.ext.commands.Bot.on_command_error

https://discordpy.readthedocs.io/en/stable/ext/commands/api.html?highlight=context#discord.ext.commands.Context.command

Upvotes: 2

Related Questions