Skip to content

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:

add_row

Add an action row to this container.

Parameters:

Returns:

add_section

Add a section to this container.

Parameters:

  • section (Section) –

    the Section object

Returns:

add_text_display

Add a text display to this container.

Parameters:

  • content (str) –

    the content to display

Returns:

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:

Add a media gallery to this container.

Parameters:

Returns:

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:

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:


Section dataclass

Bases: DataModel, ContainerChild

Represents the Section component.

accessory: Optional[SectionAccessory] = None class-attribute instance-attribute

components: list[SectionChild] = field(default_factory=list) class-attribute instance-attribute


MediaGalleryItem dataclass

Bases: DataModel

Represents the Media Gallery Item component.

media: str instance-attribute

Image data. http or attachment:// scheme.

description: Optional[str] = None class-attribute instance-attribute

Alt text for the media.

spoiler: Optional[bool] = False class-attribute instance-attribute

If the media should be blurred out.


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:

Returns:

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: