From b9c7b051763e11d2e3f9b526b4773c9e842a479f Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 5 Jun 2016 00:35:27 -0400 Subject: [PATCH] [commands] Unify Command.handle_local_error into general dispatcher. --- discord/ext/commands/bot.py | 3 +-- discord/ext/commands/core.py | 17 ++++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 8814021b6..6fc36a3ce 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -641,8 +641,7 @@ class Bot(GroupMixin, discord.Client): try: yield from command.invoke(ctx) except CommandError as e: - command.handle_local_error(e, ctx) - self.dispatch('command_error', e, ctx) + command.dispatch_error(e, ctx) else: self.dispatch('command_completion', command, ctx) else: diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index fb60274bb..dd3607f5e 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -137,17 +137,20 @@ class Command: self.instance = None self.parent = None - def handle_local_error(self, error, ctx): + def dispatch_error(self, error, ctx): try: coro = self.on_error except AttributeError: - return - - injected = inject_context(ctx, coro) - if self.instance is not None: - discord.compat.create_task(injected(self.instance, error, ctx), loop=ctx.bot.loop) + pass else: - discord.compat.create_task(injected(error, ctx), loop=ctx.bot.loop) + loop = ctx.bot.loop + injected = inject_context(ctx, coro) + if self.instance is not None: + discord.compat.create_task(injected(self.instance, error, ctx), loop=loop) + else: + discord.compat.create_task(injected(error, ctx), loop=loop) + finally: + ctx.bot.dispatch('command_error', error, ctx) def _get_from_servers(self, bot, getter, argument): result = None