Python 如何防止触发多个错误实例?discord.py重写

Python 如何防止触发多个错误实例?discord.py重写,python,bots,discord,discord.py,discord.py-rewrite,Python,Bots,Discord,Discord.py,Discord.py Rewrite,所以我为我的discord机器人做了一个错误处理程序。我相信我已经把所有的例子都放进了if语句中。但是,当发生错误时,它一次发送2-3条错误实例消息。我怎样才能解决这个问题?我在想一个错误信息计数器,但我不知道如何做 这是我的处理程序: 错误处理程序 提前感谢 您没有指定是否收到不同的错误实例消息,但是由于您的if语句只是if语句而不是if else语句,因此如果一个错误的类型不止一种,那么两个错误消息都将被输出。如果我将if语句放在一个if语句中,并在它们之间加上一个“or”,这会解决问题吗?

所以我为我的discord机器人做了一个错误处理程序。我相信我已经把所有的例子都放进了if语句中。但是,当发生错误时,它一次发送2-3条错误实例消息。我怎样才能解决这个问题?我在想一个错误信息计数器,但我不知道如何做

这是我的处理程序:

错误处理程序
提前感谢

您没有指定是否收到不同的错误实例消息,但是由于您的if语句只是if语句而不是if else语句,因此如果一个错误的类型不止一种,那么两个错误消息都将被输出。

如果我将if语句放在一个if语句中,并在它们之间加上一个“or”,这会解决问题吗?这样行吗?不,我的意思是用elif替换第一个if之后的if语句,这样一旦其中一条消息被打印出来,它就不会检查其他if语句。这样行了吗,谢谢。这些都是错误实例吗?看起来可能有更多的错误类型,但我不完全确定它们都与您希望通过bot告诉用户的错误类型有关。link有各种各样的命令错误,但正如我所说的,由您来决定哪些命令错误与发送消息相关。
@bot.event
async def on_command_error(ctx, error):
    
    if isinstance(error, commands.CheckFailure):
        await ctx.send("[HANDLER] You do not have the required role to use this command!")
        print(error)
    if isinstance(error, commands.MissingPermissions):
        await ctx.send("[HANDLER] You do not have sufficient permission settings to use this command!")
        print(error)
    if isinstance(error, commands.UserInputError):
        await ctx.send("[HANDLER] Invalid input! You have most likely typed something wrong; check spelling and try again. Use $help for more information.")
        print(error)
    if isinstance(error, commands.CommandNotFound):
        await ctx.send("[HANDLER] That command doesn't exist! You may have typed it wrong, try again. Use $help for more information")
        print(error)
    if isinstance(error, commands.BotMissingPermissions):
        await ctx.send("[HANDLER] I'm missing the permissions to use this command!")
        print(error)
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send("[HANDLER] You missed an argument! For help do $help [command].")
        print(error)
    if isinstance(error, commands.BadArgument):
        await ctx.send("[HANDLER] Could not find that value!")
        print(error)
    if isinstance(error, commands.DisabledCommand):
        await ctx.send("[HANDLER] This command has been disabled!")
        print(error)
    if isinstance(error, commands.NoPrivateMessage):
        await ctx.send("[HANDLER] This command can not be used inside private messages!")