From c3e39cd722c9e50aa909a394f5cf31c957d0868d Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 18 May 2017 20:48:38 -0400 Subject: [PATCH] [commands] Fix Context.command_failed from being incorrect. When used, it would be set to False after the invoke was done. Ideally it should report to False during invoke but True during any error case. --- discord/ext/commands/bot.py | 1 - discord/ext/commands/context.py | 2 +- discord/ext/commands/core.py | 4 ++++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 886f9086..9a7c5023 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -742,7 +742,6 @@ class BotBase(GroupMixin): except CommandError as e: yield from ctx.command.dispatch_error(ctx, e) else: - ctx.command_failed = False self.dispatch('command_completion', ctx) elif ctx.invoked_with: exc = CommandNotFound('Command "{}" is not found'.format(ctx.invoked_with)) diff --git a/discord/ext/commands/context.py b/discord/ext/commands/context.py index 2d5ec2da..ef7d9ca6 100644 --- a/discord/ext/commands/context.py +++ b/discord/ext/commands/context.py @@ -83,7 +83,7 @@ class Context(discord.abc.Messageable): self.invoked_with = attrs.pop('invoked_with', None) self.invoked_subcommand = attrs.pop('invoked_subcommand', None) self.subcommand_passed = attrs.pop('subcommand_passed', None) - self.command_failed = attrs.pop('command_failed', True) + self.command_failed = attrs.pop('command_failed', False) self._state = self.message._state @asyncio.coroutine diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 67a5e9f5..29a0433c 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -61,10 +61,13 @@ def hooked_wrapped_callback(command, ctx, coro): try: ret = yield from coro(*args, **kwargs) except CommandError: + ctx.command_failed = True raise except asyncio.CancelledError: + ctx.command_failed = True return except Exception as e: + ctx.command_failed = True raise CommandInvokeError(e) from e finally: yield from command.call_after_hooks(ctx) @@ -165,6 +168,7 @@ class Command: @asyncio.coroutine def dispatch_error(self, ctx, error): + ctx.command_failed = True cog = self.instance try: coro = self.on_error