Skip to content

Commit

Permalink
Fix KeyError when min_value or max_value are missing.
Browse files Browse the repository at this point in the history
  • Loading branch information
izxxr authored Oct 21, 2021
1 parent d85edf1 commit ebf4b03
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions discord/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ def __init__(
for o in kwargs.pop("choices", list())
]
self.default = kwargs.pop("default", None)
self.min_value: Optional[Union[int, float]] = kwargs.pop("min_value")
self.max_value: Optional[Union[int, float]] = kwargs.pop("max_value")
self.min_value: Optional[Union[int, float]] = kwargs.pop("min_value", None)
self.max_value: Optional[Union[int, float]] = kwargs.pop("max_value", None)

if any([self.max_value, self.min_value]) and not self.input_type in {SlashCommandOptionType.integer, SlashCommandOptionType.number}:
raise TypeError('min_value and max_value can only be set on options with of type integer or number.')
Expand All @@ -544,9 +544,9 @@ def to_dict(self) -> Dict:
}
if self.channel_types:
as_dict["channel_types"] = [t.value for t in self.channel_types]
if self.min_value:
if self.min_value is not None:
as_dict["min_value"] = self.min_value
if self.max_value:
if self.max_value is not None:
as_dict["max_value"] = self.max_value

return as_dict
Expand Down

0 comments on commit ebf4b03

Please sign in to comment.