diff options
| author | Rapptz <[email protected]> | 2016-01-28 02:10:59 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-01-28 03:24:50 -0500 |
| commit | 1688d513e81383f12087d7846ce2cef4811697a4 (patch) | |
| tree | 71f4887e692daa71d83e700149dc55de957e8bd1 | |
| parent | Update README to have a valid example. (diff) | |
| download | discord.py-1688d513e81383f12087d7846ce2cef4811697a4.tar.xz discord.py-1688d513e81383f12087d7846ce2cef4811697a4.zip | |
[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.
| -rw-r--r-- | discord/ext/commands/context.py | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/discord/ext/commands/context.py b/discord/ext/commands/context.py index 8d1cd054..012f65a7 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) + |