[commands] Ensure that Context.command is the command in Command.can_run

Previously, Context.command was not guaranteed to be the actual command
being checked if it can run. This could be troublesome when
implementing help commands or when using the default help command.

This new change allows at least for the guarantee that Context.command
to be technically correct in Command.can_run.
This commit is contained in:
Rapptz 2017-06-21 02:27:16 -04:00
parent c23ef9e8a4
commit 3618f51f97

View File

@ -640,6 +640,10 @@ class Command:
A boolean indicating if the command can be invoked. A boolean indicating if the command can be invoked.
""" """
original = ctx.command
ctx.command = self
try:
if not (yield from ctx.bot.can_run(ctx)): if not (yield from ctx.bot.can_run(ctx)):
raise CheckFailure('The global check functions for command {0.qualified_name} failed.'.format(self)) raise CheckFailure('The global check functions for command {0.qualified_name} failed.'.format(self))
@ -660,6 +664,8 @@ class Command:
return True return True
return (yield from discord.utils.async_all(predicate(ctx) for predicate in predicates)) return (yield from discord.utils.async_all(predicate(ctx) for predicate in predicates))
finally:
ctx.command = original
class GroupMixin: class GroupMixin:
"""A mixin that implements common functionality for classes that behave """A mixin that implements common functionality for classes that behave