@@ -563,8 +563,12 @@ class SlashCommandOption:
563
563
If the :attr:`~SlashCommandOption.option_type` is one of :attr:`~OptionType.integer` or :attr:`~OptionType.number`
564
564
this is the minimum value the users input must be of.
565
565
max_value: Optional[Union[:class:`int`, :class:`float`]]
566
- If the :attr:`option_type` is one of :class:`OptionType.integer` or :class:`OptionType.number`
566
+ If the :attr:`option_type` is one of :class:`~ OptionType.integer` or :class:`~ OptionType.number`
567
567
this is the maximum value the users input could be of.
568
+ min_length: :class:`int`
569
+ If the :attr:`option_type` is :class:`~OptionType.string`, this is the minimum length (min. of ``0``)
570
+ max_length: :class:`int`
571
+ If the :attr:`option_type` is :class:`~OptionType.string`, this is the maximum length (min. of ``1``)
568
572
channel_types: Optional[List[Union[:class:`abc.GuildChannel`, :class:`ChannelType`, :class:`int`]]]
569
573
A list of :class:`ChannelType` or the type itself like ``TextChannel`` or ``StageChannel`` the user could select.
570
574
Only valid if :attr:`~SlashCommandOption.option_type` is :class:`OptionType.channel`.
@@ -589,6 +593,8 @@ def __init__(self,
589
593
autocomplete : bool = False ,
590
594
min_value : Optional [Union [int , float ]] = None ,
591
595
max_value : Optional [Union [int , float ]] = None ,
596
+ min_length : int = None ,
597
+ max_length : int = None ,
592
598
channel_types : Optional [List [Union [type (GuildChannel ), ChannelType , int ]]] = None ,
593
599
default : Optional [Any ] = None ,
594
600
converter : Optional ['Converter' ] = None ,
@@ -626,6 +632,8 @@ def __init__(self,
626
632
self .autocomplete : bool = autocomplete
627
633
self .min_value : Optional [Union [int , float ]] = min_value
628
634
self .max_value : Optional [Union [int , float ]] = max_value
635
+ self .min_length : int = min_length
636
+ self .max_length : int = max_length
629
637
for index , choice in enumerate (choices ): # TODO: find a more efficient way to do this
630
638
if not isinstance (choice , SlashCommandOptionChoice ):
631
639
choices [index ] = SlashCommandOptionChoice (choice )
@@ -769,6 +777,13 @@ def to_dict(self) -> dict:
769
777
base ['min_value' ] = self .min_value
770
778
if self .max_value is not None :
771
779
base ['max_value' ] = self .max_value
780
+ if self .type .string :
781
+ min_length = self .min_length
782
+ max_length = self .max_length
783
+ if min_length :
784
+ base ['min_length' ] = min_length
785
+ if max_length :
786
+ base ['max_length' ] = max_length
772
787
if self .channel_types :
773
788
base ['channel_types' ] = [int (ch_type ) for ch_type in self .channel_types ]
774
789
return base
@@ -790,7 +805,9 @@ def from_dict(cls, data) -> SlashCommandOption:
790
805
choices = [SlashCommandOptionChoice .from_dict (c ) for c in data .get ('choices' , [])],
791
806
autocomplete = data .get ('autocomplete' , False ),
792
807
min_value = data .get ('min_value' , None ),
793
- max_value = data .get ('max_value' , None )
808
+ max_value = data .get ('max_value' , None ),
809
+ min_length = data .get ('min_length' , None ),
810
+ max_length = data .get ('max_length' , None )
794
811
)
795
812
796
813
0 commit comments