[commands] Unify Command.handle_local_error into general dispatcher.

This commit is contained in:
Rapptz 2016-06-05 00:35:27 -04:00
parent 661645ac97
commit b9c7b05176
2 changed files with 11 additions and 9 deletions

View File

@ -641,8 +641,7 @@ class Bot(GroupMixin, discord.Client):
try: try:
yield from command.invoke(ctx) yield from command.invoke(ctx)
except CommandError as e: except CommandError as e:
command.handle_local_error(e, ctx) command.dispatch_error(e, ctx)
self.dispatch('command_error', e, ctx)
else: else:
self.dispatch('command_completion', command, ctx) self.dispatch('command_completion', command, ctx)
else: else:

View File

@ -137,17 +137,20 @@ class Command:
self.instance = None self.instance = None
self.parent = None self.parent = None
def handle_local_error(self, error, ctx): def dispatch_error(self, error, ctx):
try: try:
coro = self.on_error coro = self.on_error
except AttributeError: except AttributeError:
return pass
else:
loop = ctx.bot.loop
injected = inject_context(ctx, coro) injected = inject_context(ctx, coro)
if self.instance is not None: if self.instance is not None:
discord.compat.create_task(injected(self.instance, error, ctx), loop=ctx.bot.loop) discord.compat.create_task(injected(self.instance, error, ctx), loop=loop)
else: else:
discord.compat.create_task(injected(error, ctx), loop=ctx.bot.loop) 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): def _get_from_servers(self, bot, getter, argument):
result = None result = None