Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
530 views
in Technique[技术] by (71.8m points)

python - discord.py wrong command message

I'm having some issues making a custom error message when a wrong command is used on discord.

The code is:

@client.event
async def on_message_error(ctx, error):
    if isinstance(error, discord.ext.commands.errors.CommandNotFound):
        await ctx.send("Unknown command")

If I use wrong command, the following will appear in the console:

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

But the discord bot does not send the "Unknow command" message.

What am I doing wrong?

question from:https://stackoverflow.com/questions/65918735/discord-py-wrong-command-message

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Like ?ukasz said, replace your on_message_error with on_command_error. You can view this in the docs here.

@client.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandNotFound): # or discord.ext.commands.errors.CommandNotFound as you wrote
        await ctx.send("Unknown command")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...