Skip to content

Commit 87429ac

Browse files
authored
Merge pull request #295 from nerdguyahmad/feature/min-max-value
Add min_value & max_value to Option
2 parents 2bbf063 + a43de79 commit 87429ac

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

discord/commands/commands.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,21 @@ def __init__(
575575
for o in kwargs.pop("choices", list())
576576
]
577577
self.default = kwargs.pop("default", None)
578+
if self.input_type == SlashCommandOptionType.integer:
579+
minmax_types = (int,)
580+
elif self.input_type == SlashCommandOptionType.number:
581+
minmax_types = (int, float)
582+
else:
583+
minmax_types = (None,)
584+
minmax_types = Optional[Union[minmax_types]]
585+
586+
self.min_value: minmax_types = kwargs.pop("min_value", None)
587+
self.max_value: minmax_types = kwargs.pop("max_value", None)
588+
589+
if not isinstance(self.min_value, minmax_types.__args__) or self.min_value is None:
590+
raise TypeError(f"Expected {minmax_types} for min_value, got \"{type(self.min_value).__name__}\"")
591+
if not isinstance(self.max_value, minmax_types.__args__) or self.max_value is None:
592+
raise TypeError(f"Expected {minmax_types} for max_value, got \"{type(self.max_value).__name__}\"")
578593

579594
def to_dict(self) -> Dict:
580595
as_dict = {
@@ -586,6 +601,10 @@ def to_dict(self) -> Dict:
586601
}
587602
if self.channel_types:
588603
as_dict["channel_types"] = [t.value for t in self.channel_types]
604+
if self.min_value is not None:
605+
as_dict["min_value"] = self.min_value
606+
if self.max_value is not None:
607+
as_dict["max_value"] = self.max_value
589608

590609
return as_dict
591610

0 commit comments

Comments
 (0)