From d9cd4a35612b72ffc08877b465ce97d9b079b4cb Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 21 Jan 2020 04:27:20 -0500 Subject: [PATCH] [commands] Implement Command.__call__ --- discord/ext/commands/core.py | 18 ++++++++++++++++++ docs/ext/commands/api.rst | 1 + 2 files changed, 19 insertions(+) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 3404ef163..9816ce507 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -335,6 +335,24 @@ class Command(_BaseCommand): """ 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): other._before_invoke = self._before_invoke other._after_invoke = self._after_invoke diff --git a/docs/ext/commands/api.rst b/docs/ext/commands/api.rst index 6147d16b9..8dfeec377 100644 --- a/docs/ext/commands/api.rst +++ b/docs/ext/commands/api.rst @@ -73,6 +73,7 @@ Command .. autoclass:: discord.ext.commands.Command :members: + :special-members: __call__ .. autoclass:: discord.ext.commands.Group :members: