Discord.py-Rewrite Sending an Error message when there is an unknown command or other error

前端 未结 1 1934
生来不讨喜
生来不讨喜 2021-01-29 02:23

I want to be able to send a message like await ctx.send("Error: Unknown command. Do -help for acceptable commands." or something like that (FYI, I\'m not

相关标签:
1条回答
  • 2021-01-29 03:20

    Discord.py has a on_command_error event, which takes the error as argument. You can use it this way:

    @bot.event
    async def on_command_error(ctx, error):
        await ctx.send(f"An error occured: {str(error)}")
    

    Here's a list of every discord exeptions.
    If you want a custom message for each error, you can do it this way:

    @bot.event
    async def on_message_error(ctx, error):
        if isinstance(error, discord.ext.commands.errors.CommandNotFound):
            await ctx.send("Unknown command")
    
    0 讨论(0)
提交回复
热议问题