@@ -77,26 +77,31 @@ class SelectMenu(ComponentMixin):
77
77
placeholder="Check out my options. :)",
78
78
custom_id="menu_component",
79
79
)
80
- :ivar ComponentType type: The type of select menu. Always defaults to ``3``.
80
+ :ivar ComponentType type: The type of select menu. If not given, it defaults to ``ComponentType.SELECT`` (``STRING_SELECT``)
81
81
:ivar str custom_id: The customized "ID" of the select menu.
82
- :ivar List[SelectOption] options: The list of select options in the select menu.
82
+ :ivar Optional[ List[SelectOption]] options: The list of select options in the select menu. This only applies to String-based selects .
83
83
:ivar Optional[str] placeholder?: The placeholder of the select menu.
84
84
:ivar Optional[int] min_values?: The minimum "options"/values to choose from the component.
85
85
:ivar Optional[int] max_values?: The maximum "options"/values to choose from the component.
86
86
:ivar Optional[bool] disabled?: Whether the select menu is unable to be used.
87
+ :ivar Optional[List[int]] channel_types: Optional channel types to filter/whitelist. Only works with the CHANNEL_SELECT type.
87
88
"""
88
89
89
90
type : ComponentType = field (converter = ComponentType , default = ComponentType .SELECT )
90
91
custom_id : str = field ()
91
- options : List [SelectOption ] = field (converter = convert_list (SelectOption ))
92
+ options : Optional [List [SelectOption ]] = field (
93
+ converter = convert_list (SelectOption ), default = None
94
+ )
92
95
placeholder : Optional [str ] = field (default = None )
93
96
min_values : Optional [int ] = field (default = None )
94
97
max_values : Optional [int ] = field (default = None )
95
98
disabled : Optional [bool ] = field (default = None )
99
+ channel_types : Optional [List [int ]] = field (default = None )
96
100
97
101
def __attrs_post_init__ (self ) -> None :
98
102
self ._json .update ({"type" : self .type .value })
99
- self ._json .update ({"options" : [option ._json for option in self .options ]})
103
+ if self .options :
104
+ self ._json .update ({"options" : [option ._json for option in self .options ]})
100
105
101
106
102
107
@define ()
@@ -284,10 +289,14 @@ class ActionRow(ComponentMixin):
284
289
def __attrs_post_init__ (self ) -> None :
285
290
for component in self .components :
286
291
if isinstance (component , SelectMenu ):
287
- component ._json ["options" ] = [
288
- option ._json if isinstance (option , SelectOption ) else option
289
- for option in component ._json ["options" ]
290
- ]
292
+ component ._json ["options" ] = (
293
+ [
294
+ option ._json if isinstance (option , SelectOption ) else option
295
+ for option in component ._json ["options" ]
296
+ ]
297
+ if component ._json .get ("options" )
298
+ else []
299
+ )
291
300
self .components = (
292
301
[Component (** component ._json ) for component in self .components ]
293
302
if self ._json .get ("components" )
@@ -323,10 +332,14 @@ def __check_action_row():
323
332
action_row if isinstance (action_row , list ) else action_row .components
324
333
):
325
334
if isinstance (component , SelectMenu ):
326
- component ._json ["options" ] = [
327
- option if isinstance (option , dict ) else option ._json
328
- for option in component .options
329
- ]
335
+ component ._json ["options" ] = (
336
+ [
337
+ option if isinstance (option , dict ) else option ._json
338
+ for option in component .options
339
+ ]
340
+ if component ._json .get ("options" )
341
+ else []
342
+ )
330
343
331
344
_components .append (
332
345
{
@@ -367,10 +380,14 @@ def __check_components():
367
380
):
368
381
for component in components :
369
382
if isinstance (component , SelectMenu ):
370
- component ._json ["options" ] = [
371
- options if isinstance (options , dict ) else options ._json
372
- for options in component ._json ["options" ]
373
- ]
383
+ component ._json ["options" ] = (
384
+ [
385
+ options if isinstance (options , dict ) else options ._json
386
+ for options in component ._json ["options" ]
387
+ ]
388
+ if component ._json .get ("options" )
389
+ else []
390
+ )
374
391
375
392
_components = [
376
393
{
@@ -397,10 +414,14 @@ def __check_components():
397
414
return _components
398
415
elif isinstance (components , SelectMenu ):
399
416
_components : List [dict ] = [{"type" : 1 , "components" : []}]
400
- components ._json ["options" ] = [
401
- options if isinstance (options , dict ) else options ._json
402
- for options in components ._json ["options" ]
403
- ]
417
+ components ._json ["options" ] = (
418
+ [
419
+ options if isinstance (options , dict ) else options ._json
420
+ for options in components ._json ["options" ]
421
+ ]
422
+ if components ._json .get ("options" )
423
+ else []
424
+ )
404
425
405
426
_components [0 ]["components" ] = (
406
427
[components ._json ]
0 commit comments