From b4d2395a5eadc7353b00809010452acd7868875e Mon Sep 17 00:00:00 2001 From: z03h <7235242+z03h@users.noreply.github.com> Date: Sat, 16 Jul 2022 19:27:47 -0700 Subject: [PATCH] [commands] change Range to raise BadArgument for invalid values --- discord/ext/commands/converter.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index e3cba683e..2cabc858a 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -1049,8 +1049,9 @@ else: Inside a :class:`HybridCommand` this functions equivalently to :class:`discord.app_commands.Range`. - If the converter fails then :class:`~.ext.commands.RangeError` is raised to - the appropriate error handlers. + If the value cannot be converted to the provided type or is outside the given range, + :class:`~.ext.commands.BadArgument` or :class:`~.ext.commands.RangeError` is raised to + the appropriate error handlers respectively. .. versionadded:: 2.0 @@ -1076,7 +1077,13 @@ else: self.max: Optional[Union[int, float]] = max async def convert(self, ctx: Context[BotT], value: str) -> Union[int, float]: - count = converted = self.annotation(value) + try: + count = converted = self.annotation(value) + except ValueError: + raise BadArgument( + f'Converting to "{self.annotation.__name__}" failed for parameter "{ctx.current_parameter.name}".' + ) + if self.annotation is str: count = len(value)