aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-07-18 17:40:52 -0400
committerRapptz <[email protected]>2017-07-18 17:58:38 -0400
commitbcaee518a1bc30dc560ab4b94724c95cf106ee91 (patch)
tree5452748e812f2d94b329e40430ddc705db8c7d0d
parentImplement new-style NSFW channels. (diff)
downloaddiscord.py-bcaee518a1bc30dc560ab4b94724c95cf106ee91.tar.xz
discord.py-bcaee518a1bc30dc560ab4b94724c95cf106ee91.zip
[commands] Remove support for pass_context=False in Command.
-rw-r--r--discord/ext/commands/bot.py1
-rw-r--r--discord/ext/commands/context.py6
-rw-r--r--discord/ext/commands/core.py23
3 files changed, 13 insertions, 17 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py
index 893719a1..55c97301 100644
--- a/discord/ext/commands/bot.py
+++ b/discord/ext/commands/bot.py
@@ -168,7 +168,6 @@ class BotBase(GroupMixin):
self._skip_check = lambda x, y: x == y
self.help_attrs = options.pop('help_attrs', {})
- self.help_attrs['pass_context'] = True
if 'name' not in self.help_attrs:
self.help_attrs['name'] = 'help'
diff --git a/discord/ext/commands/context.py b/discord/ext/commands/context.py
index 8d49ad1e..5635542d 100644
--- a/discord/ext/commands/context.py
+++ b/discord/ext/commands/context.py
@@ -32,7 +32,7 @@ class Context(discord.abc.Messageable):
This class contains a lot of meta data to help you understand more about
the invocation context. This class is not created manually and is instead
- passed around to commands by passing in :attr:`Command.pass_context`.
+ passed around to commands as the first parameter.
This class implements the :class:`abc.Messageable` ABC.
@@ -122,9 +122,7 @@ class Context(discord.abc.Messageable):
if command.instance is not None:
arguments.append(command.instance)
- if command.pass_context:
- arguments.append(self)
-
+ arguments.append(self)
arguments.extend(args[1:])
ret = yield from command.callback(*arguments, **kwargs)
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py
index cc8dd8bf..d7e562d5 100644
--- a/discord/ext/commands/core.py
+++ b/discord/ext/commands/core.py
@@ -104,9 +104,6 @@ class Command:
A replacement for arguments in the default help text.
aliases: list
The list of aliases the command can be invoked under.
- pass_context: bool
- A boolean that indicates that the current :class:`.Context` should
- be passed as the **first parameter**. Defaults to `True`.
enabled: bool
A boolean that indicates if the command is currently enabled.
If the command is invoked while it is disabled, then
@@ -152,7 +149,6 @@ class Command:
self.usage = kwargs.get('usage')
self.rest_is_raw = kwargs.get('rest_is_raw', False)
self.aliases = kwargs.get('aliases', [])
- self.pass_context = kwargs.get('pass_context', True)
self.description = inspect.cleandoc(kwargs.get('description', ''))
self.hidden = kwargs.get('hidden', False)
signature = inspect.signature(callback)
@@ -272,9 +268,11 @@ class Command:
# first parameter is self
result.popitem(last=False)
- if self.pass_context:
+ try:
# first/second parameter is context
result.popitem(last=False)
+ except Exception as e:
+ raise ValueError('Missing context parameter') from None
return result
@@ -331,12 +329,11 @@ class Command:
@asyncio.coroutine
def _parse_arguments(self, ctx):
- ctx.args = [] if self.instance is None else [self.instance]
+ ctx.args = [ctx] if self.instance is None else [self.instance, ctx]
ctx.kwargs = {}
args = ctx.args
kwargs = ctx.kwargs
- first = True
view = ctx.view
iterator = iter(self.params.items())
@@ -349,12 +346,14 @@ class Command:
fmt = 'Callback for {0.name} command is missing "self" parameter.'
raise discord.ClientException(fmt.format(self))
- for name, param in iterator:
- if first and self.pass_context:
- args.append(ctx)
- first = False
- continue
+ # next we have the 'ctx' as the next parameter
+ try:
+ next(iterator)
+ except StopIteration:
+ fmt = 'Callback for {0.name} command is missing "ctx" parameter.'
+ raise discord.ClientException(fmt.format(self))
+ for name, param in iterator:
if param.kind == param.POSITIONAL_OR_KEYWORD:
transformed = yield from self.transform(ctx, param)
args.append(transformed)