diff options
| author | Rapptz <[email protected]> | 2017-06-27 04:58:20 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-06-27 04:58:20 -0400 |
| commit | ce34713c45b5c0c4b47537d0f93295a28dea3591 (patch) | |
| tree | ba340b6971239667c9e52207a8608c8bb24b3e2b | |
| parent | [commands] Add parameter that failed in fall-back BadArgument error. (diff) | |
| download | discord.py-ce34713c45b5c0c4b47537d0f93295a28dea3591.tar.xz discord.py-ce34713c45b5c0c4b47537d0f93295a28dea3591.zip | |
[commands] Do not take up 'command' keyword-argument in Context.invoke.
It was annoying when commands would have a keyword-only argument
named 'command', such as a help command or a disable command.
| -rw-r--r-- | discord/ext/commands/context.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/discord/ext/commands/context.py b/discord/ext/commands/context.py index 53aecdb1..8d49ad1e 100644 --- a/discord/ext/commands/context.py +++ b/discord/ext/commands/context.py @@ -87,7 +87,7 @@ class Context(discord.abc.Messageable): self._state = self.message._state @asyncio.coroutine - def invoke(self, command, *args, **kwargs): + def invoke(self, *args, **kwargs): """|coro| Calls a command with the arguments given. @@ -99,9 +99,13 @@ class Context(discord.abc.Messageable): ------ You do not pass in the context as it is done for you. + Warning + --------- + The first parameter passed **must** be the command being invoked. + Parameters ----------- - command : :class:`.Command` + command: :class:`.Command` A command or superclass of a command that is going to be called. \*args The arguments to to use. @@ -109,6 +113,11 @@ class Context(discord.abc.Messageable): The keyword arguments to use. """ + try: + command = args[0] + except IndexError: + raise TypeError('Missing command to invoke.') from None + arguments = [] if command.instance is not None: arguments.append(command.instance) @@ -116,7 +125,7 @@ class Context(discord.abc.Messageable): if command.pass_context: arguments.append(self) - arguments.extend(args) + arguments.extend(args[1:]) ret = yield from command.callback(*arguments, **kwargs) return ret |