UI Components API (COMPONENTS_V2)¶
Note
The following classes come from the discord.parts.components_v2
module.
Important
Any message with Container components MUST HAVE the message flag IS_COMPONENTS_V2
!
Container
dataclass
¶
Bases: DataModel
Represents a container of display and interactable components.
components: list[ContainerChild] = field(default_factory=list)
class-attribute
instance-attribute
¶
Child components that are encapsulated within the Container.
accent_color: Optional[int] = None
class-attribute
instance-attribute
¶
Color for the accent as an integer.
spoiler: Optional[bool] = False
class-attribute
instance-attribute
¶
If the container should be blurred out.
set_color
¶
Set this container's color with a hex. (format: #FFFFFF)
Parameters:
-
hex
(str
) –color as a hex code
Returns:
-
Container
–self
add_row
¶
add_section
¶
add_text_display
¶
Add a text display to this container.
Parameters:
-
content
(str
) –the content to display
Returns:
-
Container
–self
set_thumbnail
¶
Set the thumbnail for this container
Parameters:
-
media
(str
) –Image data. http or attachment://
scheme. -
description
(str
, default:None
) –Alt text for the media
-
has_spoiler
(bool
, default:False
) –If the media should be blurred out. Defaults to False.
Returns:
-
Container
–self
set_media_gallery
¶
Add a media gallery to this container.
Parameters:
-
items
(list[MediaGalleryItem]
) –list of media gallery images
Returns:
-
Container
–self
add_attachment
¶
Add a single attachment to this container.
Parameters:
-
file
(str
) –Image data. http or attachment://
scheme -
has_spoiler
(bool
, default:False
) –If the media should be blurred out. Defaults to False.
Returns:
-
Container
–self
add_separator
¶
Add a separator to this container. Positionally accurate.
Parameters:
-
spacing
(Literal['Small', 'Large']
, default:'Small'
) –size of separator padding. Defaults to 'Small'.
-
has_divider
(bool
, default:True
) –if a visual divider should be shown. Defaults to True.
Returns:
-
Container
–self
Section
dataclass
¶
Label
dataclass
¶
Bases: DataModel
Represents the Discord Label component.
label: str
instance-attribute
¶
Label text.
component: LabelChild = None
class-attribute
instance-attribute
¶
A component within the label.
description: Optional[str] = None
class-attribute
instance-attribute
¶
An optional description text for the label.
string_select
¶
Set this label to be a string select component.
Parameters:
-
select
(StringSelect
) –the string select component
Returns:
-
Label
–self
text_input
¶
Set this label to be a text input component.
Parameters:
-
custom_id
(str
) –developer-defined component ID
-
min_length
(int
) –minimum number of characters required
-
max_length
(int
) –maximum number of characters required
-
value
(str
, default:None
) –component value
-
style
(Literal['Short', 'Paragraph']
, default:'Short'
) –text format. Defaults to 'Short'.
-
placeholder
(str
, default:None
) –custom placeholder text if empty
-
require
(bool
, default:False
) –if input is required. Defaults to False.
Returns:
-
Label
–self