[commands] Implement Command.__call__

This commit is contained in:
Rapptz 2020-01-21 04:27:20 -05:00
parent 02397306b2
commit d9cd4a3561
2 changed files with 19 additions and 0 deletions

View File

@ -335,6 +335,24 @@ class Command(_BaseCommand):
""" """
self.__init__(self.callback, **dict(self.__original_kwargs__, **kwargs)) self.__init__(self.callback, **dict(self.__original_kwargs__, **kwargs))
async def __call__(self, *args, **kwargs):
"""|coro|
Calls the internal callback that the command holds.
.. note::
This bypasses all mechanisms -- including checks, converters,
invoke hooks, cooldowns, etc. You must take care to pass
the proper arguments and types to this function.
.. versionadded:: 1.3
"""
if self.cog is not None:
return await self.callback(self.cog, *args, **kwargs)
else:
return await self.callback(*args, **kwargs)
def _ensure_assignment_on_copy(self, other): def _ensure_assignment_on_copy(self, other):
other._before_invoke = self._before_invoke other._before_invoke = self._before_invoke
other._after_invoke = self._after_invoke other._after_invoke = self._after_invoke

View File

@ -73,6 +73,7 @@ Command
.. autoclass:: discord.ext.commands.Command .. autoclass:: discord.ext.commands.Command
:members: :members:
:special-members: __call__
.. autoclass:: discord.ext.commands.Group .. autoclass:: discord.ext.commands.Group
:members: :members: