aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkhazhyk <[email protected]>2020-09-07 19:24:48 -0700
committerGitHub <[email protected]>2020-09-07 22:24:48 -0400
commit6349d37a97177a026d88d0f617a5f1ffca6a517d (patch)
tree43a775caeb0c8f94df6d758df0bec86151de2977
parent[commands] BadBooleanArgument -> BadBoolArgument (diff)
downloaddiscord.py-6349d37a97177a026d88d0f617a5f1ffca6a517d.tar.xz
discord.py-6349d37a97177a026d88d0f617a5f1ffca6a517d.zip
[commands] add require_var_positional
-rw-r--r--discord/ext/commands/core.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py
index 8e3ad3f2..c33d1d52 100644
--- a/discord/ext/commands/core.py
+++ b/discord/ext/commands/core.py
@@ -179,6 +179,12 @@ class Command(_BaseCommand):
in a completely raw matter. Defaults to ``False``.
invoked_subcommand: Optional[:class:`Command`]
The subcommand that was invoked, if any.
+ require_var_positional: :class:`bool`
+ If ``True`` and a variadic positional argument is specified, requires
+ the user to specify at least one argument. Defaults to ``False``.
+
+ .. versionadded:: 1.5
+
ignore_extra: :class:`bool`
If ``True``\, ignores extraneous strings passed to a command if all its
requirements are met (e.g. ``?foo a b c`` when only expecting ``a``
@@ -260,6 +266,7 @@ class Command(_BaseCommand):
finally:
self._max_concurrency = max_concurrency
+ self.require_var_positional = kwargs.get('require_var_positional', False)
self.ignore_extra = kwargs.get('ignore_extra', True)
self.cooldown_after_parsing = kwargs.get('cooldown_after_parsing', False)
self.cog = None
@@ -699,6 +706,8 @@ class Command(_BaseCommand):
kwargs[name] = await self.transform(ctx, param)
break
elif param.kind == param.VAR_POSITIONAL:
+ if view.eof and self.require_var_positional:
+ raise MissingRequiredArgument(param)
while not view.eof:
try:
transformed = await self.transform(ctx, param)
@@ -1009,7 +1018,10 @@ class Command(_BaseCommand):
result.append('[%s]' % name)
elif param.kind == param.VAR_POSITIONAL:
- result.append('[%s...]' % name)
+ if self.require_var_positional:
+ result.append('<%s...>' % name)
+ else:
+ result.append('[%s...]' % name)
elif greedy:
result.append('[%s]...' % name)
elif self._is_typing_optional(param.annotation):