From 1688d513e81383f12087d7846ce2cef4811697a4 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 28 Jan 2016 02:10:59 -0500 Subject: [PATCH] [commands] Context.invoke just invokes a command with no special case. Previously it would both forward and invoke depending if there were no kwargs given. Now it just passes in the arguments to another command without doing any special casing on the no argument case. --- discord/ext/commands/context.py | 38 ++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/discord/ext/commands/context.py b/discord/ext/commands/context.py index 8d1cd0546..012f65a73 100644 --- a/discord/ext/commands/context.py +++ b/discord/ext/commands/context.py @@ -81,8 +81,36 @@ class Context: self.subcommand_passed = attrs.pop('subcommand_passed', None) @asyncio.coroutine - def invoke(self, command, **kwargs): - if len(kwargs) == 0: - yield from command.invoke(self) - else: - yield from command.callback(**kwargs) + def invoke(self, command, *args, **kwargs): + """|coro| + + Calls a command with the arguments given. + + This is useful if you want to just call the callback that a + :class:`Command` holds internally. + + Note + ------ + You do not pass in the context as it is done for you. + + Parameters + ----------- + command : :class:`Command` + A command or superclass of a command that is going to be called. + \*args + The arguments to to use. + \*\*kwargs + The keyword arguments to use. + """ + + arguments = [] + if command.instance is not None: + arguments.append(command.instance) + + if command.pass_context: + arguments.append(self) + + arguments.extend(args) + + yield from command.callback(*arguments, **kwargs) +