Как я могу предотвратить запуск нескольких экземпляров ошибок? discord.py переписать - PullRequest
0 голосов
/ 22 апреля 2020

Так что я делаю обработчик ошибок для моего бота. Я полагаю, что у меня есть все экземпляры, помещенные в заявления if. Однако, когда происходит ошибка, она отправляет 2-3 сообщения об ошибках одновременно. Как я могу это исправить? Я думал о счетчике сообщений об ошибках, но я не уверен, как это сделать.

Вот мой обработчик:

Обработчик ошибок

@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!")

Заранее спасибо! !!

1 Ответ

1 голос
/ 22 апреля 2020

Вы не указали, получаете ли вы разные сообщения об ошибках, но поскольку ваши операторы if являются просто операторами if, а не if else, если ошибка более одного типа, будут выведены оба сообщения об ошибке.

...