[commands] Add cog local error handlers via __error.
This commit is contained in:
parent
7bc3750c27
commit
bf11bb4b4f
@ -167,16 +167,25 @@ class Command:
|
|||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def dispatch_error(self, error, ctx):
|
def dispatch_error(self, error, ctx):
|
||||||
|
cog = self.instance
|
||||||
try:
|
try:
|
||||||
coro = self.on_error
|
coro = self.on_error
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
injected = wrap_callback(coro)
|
injected = wrap_callback(coro)
|
||||||
if self.instance is not None:
|
if cog is not None:
|
||||||
yield from injected(self.instance, error, ctx)
|
yield from injected(cog, error, ctx)
|
||||||
else:
|
else:
|
||||||
yield from injected(error, ctx)
|
yield from injected(error, ctx)
|
||||||
|
|
||||||
|
try:
|
||||||
|
local = getattr(cog, '_{0.__class__.__name__}__error'.format(cog))
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
wrapped = wrap_callback(local)
|
||||||
|
yield from wrapped(error, ctx)
|
||||||
finally:
|
finally:
|
||||||
ctx.bot.dispatch('command_error', error, ctx)
|
ctx.bot.dispatch('command_error', error, ctx)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user