Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1201.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|commands| Add support for ``Range[LargeInt, ...]`` in slash command parameters.
4 changes: 2 additions & 2 deletions disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ def __init__(
self.required: bool = required
self.options: list[Option] = options or []

if min_value and self.type is OptionType.integer:
if min_value is not None and self.type is OptionType.integer:
min_value = math.ceil(min_value)
if max_value and self.type is OptionType.integer:
if max_value is not None and self.type is OptionType.integer:
max_value = math.floor(max_value)

self.min_value: float | None = min_value
Expand Down
34 changes: 33 additions & 1 deletion disnake/ext/commands/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"PartialEmojiConversionFailure",
"BadBoolArgument",
"LargeIntConversionFailure",
"LargeIntOutOfRange",
"MissingRole",
"BotMissingRole",
"MissingAnyRole",
Expand Down Expand Up @@ -570,7 +571,38 @@ class LargeIntConversionFailure(BadArgument):

def __init__(self, argument: str) -> None:
self.argument: str = argument
super().__init__(f"{argument} is not able to be converted to an integer")
super().__init__(f"{argument} is not a valid base 10 integer")


class LargeIntOutOfRange(LargeIntConversionFailure):
"""Exception raised when an argument to a large integer option exceeds given range.

This inherits from :exc:`LargeIntConversionFailure`

.. versionadded:: |vnext|

Attributes
----------
argument: :class:`str`
The argument that exceeded the defined range.
min_value: :class:`int` | :data:`None`
The minimum allowed value.
max_value: :class:`int` | :data:`None`
The maximum allowed value.
"""

def __init__(
self,
argument: str,
min_value: int | None,
max_value: int | None,
) -> None:
self.argument: str = argument
self.min_value: int | None = min_value
self.max_value: int | None = max_value
a = "..." if min_value is None else min_value
b = "..." if max_value is None else max_value
BadArgument.__init__(self, f"{argument} is not in range [{a}, {b}]")


class DisabledCommand(CommandError):
Expand Down
Loading
Loading