From ce34713c45b5c0c4b47537d0f93295a28dea3591 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 27 Jun 2017 04:58:20 -0400 Subject: [PATCH] [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. --- discord/ext/commands/context.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/discord/ext/commands/context.py b/discord/ext/commands/context.py index 53aecdb1b..8d49ad1e7 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