From 6349d37a97177a026d88d0f617a5f1ffca6a517d Mon Sep 17 00:00:00 2001 From: khazhyk Date: Mon, 7 Sep 2020 19:24:48 -0700 Subject: [PATCH] [commands] add require_var_positional --- discord/ext/commands/core.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 8e3ad3f28..c33d1d52e 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):