@@ -349,7 +349,7 @@ def __init__(self, options, custom_id=None, min_values=1, max_values=1, placehol
349
349
```
350
350
"""
351
351
UseableComponent .__init__ (self , ComponentType .Select )
352
- self ._options = None
352
+ self .options : List [ SelectOption ] = options or None
353
353
354
354
self .max_values : int = 0
355
355
"""The maximum number of items that can be chosen; default 1, max 25"""
@@ -365,7 +365,6 @@ def __init__(self, options, custom_id=None, min_values=1, max_values=1, placehol
365
365
Custom placeholder text if nothing is selected"""
366
366
self .custom_id = custom_id or '' .join ([choice (string .ascii_letters ) for _ in range (100 )])
367
367
self .disabled = disabled
368
- self .options = options
369
368
370
369
if min_values is not None and max_values is None :
371
370
if min_values < 0 or min_values > 25 :
@@ -394,26 +393,12 @@ def __repr__(self) -> str:
394
393
395
394
@staticmethod
396
395
def _from_data (data ) -> SelectMenu :
397
- return SelectMenu (data ["options" ], data ["custom_id" ], data .get ("min_values" ), data .get ("max_values" ), data .get ("placeholder" ), disabled = data .get ("disabled" , False ))
396
+ return SelectMenu ([
397
+ SelectOption ._from_data (d ) for d in data ["options" ]
398
+ ], data ["custom_id" ], data .get ("min_values" ), data .get ("max_values" ), data .get ("placeholder" ), disabled = data .get ("disabled" , False )
399
+ )
398
400
# region props
399
- @property
400
- def options (self ) -> List [SelectOption ]:
401
- """The options in the select menu to select from"""
402
- return [SelectOption ._from_data (x ) for x in self ._options ]
403
- @options .setter
404
- def options (self , value : List [SelectOption ]):
405
- if isinstance (value , list ):
406
- if len (value ) > 25 or len (value ) == 0 :
407
- raise OutOfValidRange ("length of options" , 1 , 25 )
408
- if all (isinstance (x , SelectOption ) for x in value ):
409
- self ._options = [x .to_dict () for x in value ]
410
- elif all (isinstance (x , dict ) for x in value ):
411
- self ._options = value
412
- else :
413
- raise WrongType ("options" , value , ["List[SelectOption]" , "List[dict]" ])
414
- else :
415
- raise WrongType ("options" , value , "list" )
416
-
401
+
417
402
@property
418
403
def default_options (self ) -> List [SelectOption ]:
419
404
"""The option selected by default"""
@@ -433,17 +418,17 @@ def set_default_option(self, position) -> SelectMenu:
433
418
if isinstance (position , int ):
434
419
if position < 0 or position >= len (self .options ):
435
420
raise OutOfValidRange ("default option position" , 0 , str (len (self .options ) - 1 ))
436
- self ._options [position ].default = True
421
+ self .options [position ].default = True
437
422
return self
438
423
for pos in position :
439
- self ._options [pos ].default = True
424
+ self .options [pos ].default = True
440
425
# endregion
441
426
442
427
def to_dict (self ) -> dict :
443
428
payload = {
444
429
"type" : self ._component_type ,
445
430
"custom_id" : self ._custom_id ,
446
- "options" : self ._options ,
431
+ "options" : [ x . to_dict () for x in self .options ] ,
447
432
"disabled" : self .disabled ,
448
433
"min_values" : self .min_values ,
449
434
"max_values" : self .max_values
0 commit comments