34
34
ChannelType ,
35
35
ComponentType ,
36
36
InputTextStyle ,
37
+ SelectDefaultValueType ,
37
38
SeparatorSpacingSize ,
38
39
try_enum ,
39
40
)
44
45
if TYPE_CHECKING :
45
46
from .emoji import AppEmoji , GuildEmoji
46
47
from .types .components import ActionRow as ActionRowPayload
47
- from .types .components import BaseComponent as BaseComponentPayload
48
48
from .types .components import ButtonComponent as ButtonComponentPayload
49
49
from .types .components import Component as ComponentPayload
50
50
from .types .components import ContainerComponent as ContainerComponentPayload
60
60
from .types .components import TextDisplayComponent as TextDisplayComponentPayload
61
61
from .types .components import ThumbnailComponent as ThumbnailComponentPayload
62
62
from .types .components import UnfurledMediaItem as UnfurledMediaItemPayload
63
+ from .types .components import SelectDefaultValue as SelectDefaultValuePayload
63
64
64
65
__all__ = (
65
66
"Component" ,
@@ -437,6 +438,7 @@ class SelectMenu(Component):
437
438
"channel_types" ,
438
439
"disabled" ,
439
440
"required" ,
441
+ "default_values" ,
440
442
)
441
443
442
444
__repr_info__ : ClassVar [tuple [str , ...]] = __slots__
@@ -457,6 +459,7 @@ def __init__(self, data: SelectMenuPayload):
457
459
try_enum (ChannelType , ct ) for ct in data .get ("channel_types" , [])
458
460
]
459
461
self .required : bool | None = data .get ("required" )
462
+ self .default_values : list [SelectDefaultValue ] = SelectDefaultValue ._from_data (data .get ("default_values" ))
460
463
461
464
def to_dict (self ) -> SelectMenuPayload :
462
465
payload : SelectMenuPayload = {
@@ -476,10 +479,50 @@ def to_dict(self) -> SelectMenuPayload:
476
479
payload ["placeholder" ] = self .placeholder
477
480
if self .required is not None :
478
481
payload ["required" ] = self .required
482
+ if self .type is not ComponentType .string_select :
483
+ payload ["default_values" ] = [dv .to_dict () for dv in self .default_values ]
479
484
480
485
return payload
481
486
482
487
488
+ class SelectDefaultValue :
489
+ r"""Represents a :class:`discord.SelectMenu`\s default value.
490
+
491
+ This is only applicable to selects of type other than :attr:`ComponentType.string_select`.
492
+
493
+ .. versionadded:: 2.7
494
+
495
+ Parameters
496
+ ----------
497
+ id: :class:`int`
498
+ The ID of the default value.
499
+ type: :class:`SelectDefaultValueType`
500
+ The default value type.
501
+ """
502
+
503
+ __slots__ = ("id" , "type" )
504
+
505
+ def __init__ (
506
+ self ,
507
+ id : int ,
508
+ type : SelectDefaultValueType ,
509
+ ) -> None :
510
+ self .id : int = id
511
+ self .type : SelectDefaultValueType = type
512
+
513
+ @classmethod
514
+ def _from_data (cls , default_values : list [SelectDefaultValuePayload ] | None ) -> list [SelectDefaultValue ]:
515
+ if not default_values :
516
+ return []
517
+ return [cls (id = int (d ['id' ]), type = try_enum (SelectDefaultValueType , d ['type' ])) for d in default_values ]
518
+
519
+ def to_dict (self ) -> SelectDefaultValuePayload :
520
+ return {
521
+ "id" : self .id ,
522
+ "type" : self .type .value ,
523
+ }
524
+
525
+
483
526
class SelectOption :
484
527
"""Represents a :class:`discord.SelectMenu`'s option.
485
528
0 commit comments