Skip to content

Commit a43de79

Browse files
izxxrBobDotCom
andauthored
Update discord/commands/commands.py
Co-authored-by: BobDotCom <[email protected]>
1 parent ebf4b03 commit a43de79

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

discord/commands/commands.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,21 @@ def __init__(
528528
for o in kwargs.pop("choices", list())
529529
]
530530
self.default = kwargs.pop("default", None)
531-
self.min_value: Optional[Union[int, float]] = kwargs.pop("min_value", None)
532-
self.max_value: Optional[Union[int, float]] = kwargs.pop("max_value", None)
531+
if self.input_type == SlashCommandOptionType.integer:
532+
minmax_types = (int,)
533+
elif self.input_type == SlashCommandOptionType.number:
534+
minmax_types = (int, float)
535+
else:
536+
minmax_types = (None,)
537+
minmax_types = Optional[Union[minmax_types]]
538+
539+
self.min_value: minmax_types = kwargs.pop("min_value", None)
540+
self.max_value: minmax_types = kwargs.pop("max_value", None)
533541

534-
if any([self.max_value, self.min_value]) and not self.input_type in {SlashCommandOptionType.integer, SlashCommandOptionType.number}:
535-
raise TypeError('min_value and max_value can only be set on options with of type integer or number.')
542+
if not isinstance(self.min_value, minmax_types.__args__) or self.min_value is None:
543+
raise TypeError(f"Expected {minmax_types} for min_value, got \"{type(self.min_value).__name__}\"")
544+
if not isinstance(self.max_value, minmax_types.__args__) or self.max_value is None:
545+
raise TypeError(f"Expected {minmax_types} for max_value, got \"{type(self.max_value).__name__}\"")
536546

537547
def to_dict(self) -> Dict:
538548
as_dict = {

0 commit comments

Comments
 (0)