50
50
from .types .components import ContainerComponent as ContainerComponentPayload
51
51
from .types .components import FileComponent as FileComponentPayload
52
52
from .types .components import InputText as InputTextComponentPayload
53
+ from .types .components import LabelComponent as LabelComponentPayload
53
54
from .types .components import MediaGalleryComponent as MediaGalleryComponentPayload
54
55
from .types .components import MediaGalleryItem as MediaGalleryItemPayload
55
56
from .types .components import SectionComponent as SectionComponentPayload
76
77
"FileComponent" ,
77
78
"Separator" ,
78
79
"Container" ,
80
+ "Label" ,
79
81
)
80
82
81
83
C = TypeVar ("C" , bound = "Component" )
@@ -375,6 +377,10 @@ class SelectMenu(Component):
375
377
Added support for :attr:`ComponentType.user_select`, :attr:`ComponentType.role_select`,
376
378
:attr:`ComponentType.mentionable_select`, and :attr:`ComponentType.channel_select`.
377
379
380
+ .. versionchanged:: 2.7
381
+
382
+ Added the :attr:`required` attribute for use in modals.
383
+
378
384
Attributes
379
385
----------
380
386
type: :class:`ComponentType`
@@ -398,7 +404,9 @@ class SelectMenu(Component):
398
404
Will be an empty list for all component types
399
405
except for :attr:`ComponentType.channel_select`.
400
406
disabled: :class:`bool`
401
- Whether the select is disabled or not.
407
+ Whether the select is disabled or not. Not usable in modals. Defaults to ``False``.
408
+ required: Optional[:class:`bool`]
409
+ Whether the select is required or not. Only useable in modals. Defaults to ``True``.
402
410
"""
403
411
404
412
__slots__ : tuple [str , ...] = (
@@ -409,6 +417,7 @@ class SelectMenu(Component):
409
417
"options" ,
410
418
"channel_types" ,
411
419
"disabled" ,
420
+ "required" ,
412
421
)
413
422
414
423
__repr_info__ : ClassVar [tuple [str , ...]] = __slots__
@@ -428,6 +437,7 @@ def __init__(self, data: SelectMenuPayload):
428
437
self .channel_types : list [ChannelType ] = [
429
438
try_enum (ChannelType , ct ) for ct in data .get ("channel_types" , [])
430
439
]
440
+ self .required : bool | None = data .get ("required" )
431
441
432
442
def to_dict (self ) -> SelectMenuPayload :
433
443
payload : SelectMenuPayload = {
@@ -445,6 +455,8 @@ def to_dict(self) -> SelectMenuPayload:
445
455
payload ["channel_types" ] = [ct .value for ct in self .channel_types ]
446
456
if self .placeholder :
447
457
payload ["placeholder" ] = self .placeholder
458
+ if self .required is not None :
459
+ payload ["required" ] = self .required
448
460
449
461
return payload
450
462
@@ -1037,6 +1049,55 @@ def walk_components(self) -> Iterator[Component]:
1037
1049
yield c
1038
1050
1039
1051
1052
+ class Label (Component ):
1053
+ """Represents a Label used in modals as the top-level component.
1054
+
1055
+ This is a component that allows you to add additional text to another component.
1056
+ ``component`` may only be:
1057
+
1058
+ - :class:`InputText`
1059
+ - :class:`SelectMenu` (string)
1060
+
1061
+ This inherits from :class:`Component`.
1062
+
1063
+ .. versionadded:: 2.7
1064
+
1065
+ Attributes
1066
+ ----------
1067
+ component: :class:`Component`
1068
+ The component contained in this label. Currently supports :class:`InputText` and :class:`SelectMenu`.
1069
+ label: :class:`str`
1070
+ The main text associated with this label's ``component``, up to 45 characters.
1071
+ description: Optional[:class:`str`]
1072
+ The description associated with this label's ``component``, up to 100 characters.
1073
+ """
1074
+
1075
+ __slots__ : tuple [str , ...] = ("component" , "label" , "description" )
1076
+
1077
+ __repr_info__ : ClassVar [tuple [str , ...]] = __slots__
1078
+ versions : tuple [int , ...] = ()
1079
+
1080
+ def __init__ (self , data : LabelComponentPayload ):
1081
+ self .type : ComponentType = try_enum (ComponentType , data ["type" ])
1082
+ self .id : int = data ["id" ]
1083
+ self .component : Component = _component_factory (data ["component" ])
1084
+ self .label : str = data ["label" ]
1085
+ self .description : str | None = data .get ("description" )
1086
+
1087
+ def to_dict (self ) -> LabelComponentPayload :
1088
+ payload = {
1089
+ "type" : int (self .type ),
1090
+ "id" : self .id ,
1091
+ "component" : self .component .to_dict (),
1092
+ "label" : self .label ,
1093
+ "description" : self .description ,
1094
+ }
1095
+ return payload
1096
+
1097
+ def walk_components (self ) -> Iterator [Component ]:
1098
+ yield from [self .component ]
1099
+
1100
+
1040
1101
COMPONENT_MAPPINGS = {
1041
1102
1 : ActionRow ,
1042
1103
2 : Button ,
@@ -1053,6 +1114,7 @@ def walk_components(self) -> Iterator[Component]:
1053
1114
13 : FileComponent ,
1054
1115
14 : Separator ,
1055
1116
17 : Container ,
1117
+ 18 : Label ,
1056
1118
}
1057
1119
1058
1120
STATE_COMPONENTS = (Section , Container , Thumbnail , MediaGallery , FileComponent )
0 commit comments