@@ -108,6 +108,12 @@ async def hello(
108
108
max_value: Optional[:class:`int`]
109
109
The maximum value that can be entered.
110
110
Only applies to Options with an input_type of ``int`` or ``float``.
111
+ min_length: Optional[:class:`int`]
112
+ The minimum length of the string that can be entered. Must be between 0 and 6000 (inclusive).
113
+ Only applies to Options with an input_type of ``str``.
114
+ max_length: Optional[:class:`int`]
115
+ The maximum length of the string that can be entered. Must be between 1 and 6000 (inclusive).
116
+ Only applies to Options with an input_type of ``str``.
111
117
autocomplete: Optional[:class:`Any`]
112
118
The autocomplete handler for the option. Accepts an iterable of :class:`str`, a callable (sync or async) that takes a
113
119
single argument of :class:`AutocompleteContext`, or a coroutine. Must resolve to an iterable of :class:`str`.
@@ -194,14 +200,40 @@ def __init__(self, input_type: Any = str, /, description: Optional[str] = None,
194
200
minmax_types = (type (None ),)
195
201
minmax_typehint = Optional [Union [minmax_types ]] # type: ignore
196
202
203
+ if self .input_type == SlashCommandOptionType .string :
204
+ minmax_length_types = (int , type (None ))
205
+ else :
206
+ minmax_length_types = (type (None ),)
207
+ minmax_length_typehint = Optional [Union [minmax_length_types ]] # type: ignore
208
+
197
209
self .min_value : minmax_typehint = kwargs .pop ("min_value" , None )
198
210
self .max_value : minmax_typehint = kwargs .pop ("max_value" , None )
211
+ self .min_length : minmax_length_typehint = kwargs .pop ("min_length" , None )
212
+ self .max_length : minmax_length_typehint = kwargs .pop ("max_length" , None )
199
213
200
- if not isinstance (self .min_value , minmax_types ) and self .min_value is not None :
214
+ if (input_type != SlashCommandOptionType .integer and input_type != SlashCommandOptionType .number
215
+ and (self .min_value or self .max_value )):
216
+ raise AttributeError ("Option does not take min_value or max_value if not of type "
217
+ "SlashCommandOptionType.integer or SlashCommandOptionType.number" )
218
+ if input_type != SlashCommandOptionType .string and (self .min_length or self .max_length ):
219
+ raise AttributeError ('Option does not take min_length or max_length if not of type str' )
220
+
221
+ if self .min_value is not None and not isinstance (self .min_value , minmax_types ):
201
222
raise TypeError (f'Expected { minmax_typehint } for min_value, got "{ type (self .min_value ).__name__ } "' )
202
- if not ( isinstance (self .max_value , minmax_types ) or self . min_value is None ):
223
+ if self . max_value is not None and not isinstance (self .max_value , minmax_types ):
203
224
raise TypeError (f'Expected { minmax_typehint } for max_value, got "{ type (self .max_value ).__name__ } "' )
204
225
226
+ if self .min_length is not None :
227
+ if not isinstance (self .min_length , minmax_length_types ):
228
+ raise TypeError (f'Expected { minmax_length_typehint } for min_length, got "{ type (self .min_length ).__name__ } "' )
229
+ if self .min_length < 0 or self .min_length > 6000 :
230
+ raise AttributeError ("min_length must be between 0 and 6000 (inclusive)" )
231
+ if self .max_length is not None :
232
+ if not isinstance (self .max_length , minmax_length_types ):
233
+ raise TypeError (f'Expected { minmax_length_typehint } for max_length, got "{ type (self .max_length ).__name__ } "' )
234
+ if self .max_length < 1 or self .max_length > 6000 :
235
+ raise AttributeError ("max_length must between 1 and 6000 (inclusive)" )
236
+
205
237
self .autocomplete = kwargs .pop ("autocomplete" , None )
206
238
207
239
self .name_localizations = kwargs .pop ("name_localizations" , None )
@@ -226,6 +258,10 @@ def to_dict(self) -> Dict:
226
258
as_dict ["min_value" ] = self .min_value
227
259
if self .max_value is not None :
228
260
as_dict ["max_value" ] = self .max_value
261
+ if self .min_length is not None :
262
+ as_dict ["min_length" ] = self .min_length
263
+ if self .max_length is not None :
264
+ as_dict ["max_length" ] = self .max_length
229
265
230
266
return as_dict
231
267
0 commit comments