Browse Source

[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.
pull/573/head
Rapptz 8 years ago
parent
commit
c3e39cd722
  1. 1
      discord/ext/commands/bot.py
  2. 2
      discord/ext/commands/context.py
  3. 4
      discord/ext/commands/core.py

1
discord/ext/commands/bot.py

@ -742,7 +742,6 @@ class BotBase(GroupMixin):
except CommandError as e: except CommandError as e:
yield from ctx.command.dispatch_error(ctx, e) yield from ctx.command.dispatch_error(ctx, e)
else: else:
ctx.command_failed = False
self.dispatch('command_completion', ctx) self.dispatch('command_completion', ctx)
elif ctx.invoked_with: elif ctx.invoked_with:
exc = CommandNotFound('Command "{}" is not found'.format(ctx.invoked_with)) exc = CommandNotFound('Command "{}" is not found'.format(ctx.invoked_with))

2
discord/ext/commands/context.py

@ -83,7 +83,7 @@ class Context(discord.abc.Messageable):
self.invoked_with = attrs.pop('invoked_with', None) self.invoked_with = attrs.pop('invoked_with', None)
self.invoked_subcommand = attrs.pop('invoked_subcommand', None) self.invoked_subcommand = attrs.pop('invoked_subcommand', None)
self.subcommand_passed = attrs.pop('subcommand_passed', 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 self._state = self.message._state
@asyncio.coroutine @asyncio.coroutine

4
discord/ext/commands/core.py

@ -61,10 +61,13 @@ def hooked_wrapped_callback(command, ctx, coro):
try: try:
ret = yield from coro(*args, **kwargs) ret = yield from coro(*args, **kwargs)
except CommandError: except CommandError:
ctx.command_failed = True
raise raise
except asyncio.CancelledError: except asyncio.CancelledError:
ctx.command_failed = True
return return
except Exception as e: except Exception as e:
ctx.command_failed = True
raise CommandInvokeError(e) from e raise CommandInvokeError(e) from e
finally: finally:
yield from command.call_after_hooks(ctx) yield from command.call_after_hooks(ctx)
@ -165,6 +168,7 @@ class Command:
@asyncio.coroutine @asyncio.coroutine
def dispatch_error(self, ctx, error): def dispatch_error(self, ctx, error):
ctx.command_failed = True
cog = self.instance cog = self.instance
try: try:
coro = self.on_error coro = self.on_error

Loading…
Cancel
Save