diff options
| author | Rapptz <[email protected]> | 2020-01-21 04:27:20 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-01-21 04:27:20 -0500 |
| commit | d9cd4a35612b72ffc08877b465ce97d9b079b4cb (patch) | |
| tree | 1b62ae4376d8743d33d9f5b2a44b1ef9897cc303 | |
| parent | Drop superfluous zero in version related changes in the documentation (diff) | |
| download | discord.py-d9cd4a35612b72ffc08877b465ce97d9b079b4cb.tar.xz discord.py-d9cd4a35612b72ffc08877b465ce97d9b079b4cb.zip | |
[commands] Implement Command.__call__
| -rw-r--r-- | discord/ext/commands/core.py | 18 | ||||
| -rw-r--r-- | docs/ext/commands/api.rst | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 3404ef16..9816ce50 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 6147d16b..8dfeec37 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: |