@@ -528,11 +528,21 @@ def __init__(
528
528
for o in kwargs .pop ("choices" , list ())
529
529
]
530
530
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 )
533
541
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__ } \" " )
536
546
537
547
def to_dict (self ) -> Dict :
538
548
as_dict = {
0 commit comments