Components¶
This section documents everything related to message components — a Discord feature which allows bot developers to create their own component-based UIs right inside Discord.
Warning
Classes listed below are not meant to be created by user and are only received from the API. For constructible versions, see Bot UI Kit.
Discord Models¶
Component¶
- class disnake.Component[source]¶
Represents the base component that all other components inherit from.
The components supported by Discord are:
subtypes of
BaseSelectMenu
(ChannelSelectMenu
,MentionableSelectMenu
,RoleSelectMenu
,StringSelectMenu
,UserSelectMenu
)
This class is abstract and cannot be instantiated.
Added in version 2.0.
- type¶
The type of component.
- Type:
ActionRow¶
SelectOption¶
- class disnake.SelectOption(*, label, value=..., description=None, emoji=None, default=False)[source]¶
Represents a string select menu’s option.
These can be created by users.
Added in version 2.0.
- label¶
The label of the option. This is displayed to users. Can only be up to 100 characters.
- Type:
- value¶
The value of the option. This is not displayed to users. If not provided when constructed then it defaults to the label. Can only be up to 100 characters.
- Type:
- description¶
An additional description of the option, if any. Can only be up to 100 characters.
- Type:
Optional[
str
]
- emoji¶
The emoji of the option, if available.
- Type:
Optional[Union[
str
,Emoji
,PartialEmoji
]]
SelectDefaultValue¶
- class disnake.SelectDefaultValue(id, type)[source]¶
Represents a default value of an auto-populated select menu (currently all select menu types except
StringSelectMenu
).Depending on the
type
attribute, this can represent different types of objects.Added in version 2.10.
- type¶
The type of the target object.
- Type:
TextInput¶
- class disnake.TextInput[source]¶
Represents a text input from the Discord Bot UI Kit.
Added in version 2.4.
Note
The user constructible and usable type to create a text input is
disnake.ui.TextInput
, not this one.- style¶
The style of the text input.
- Type:
Section¶
- class disnake.Section[source]¶
Represents a section from the Discord Bot UI Kit (v2).
This allows displaying an accessory (thumbnail or button) next to a block of text.
Note
The user constructible and usable type to create a section is
disnake.ui.Section
.Added in version 2.11.
- children¶
The text items in this section.
- Type:
List[
TextDisplay
]
- accessory¶
The accessory component displayed next to the section text.
TextDisplay¶
- class disnake.TextDisplay[source]¶
Represents a text display from the Discord Bot UI Kit (v2).
Note
The user constructible and usable type to create a text display is
disnake.ui.TextDisplay
.Added in version 2.11.
UnfurledMediaItem¶
- class disnake.UnfurledMediaItem[source]¶
Represents an unfurled/resolved media item within a component.
Added in version 2.11.
- proxy_url¶
The proxied URL of this media item. This is a cached version of the
url
in the case of images.- Type:
- content_type¶
The media type of this media item.
- Type:
Optional[
str
]
Thumbnail¶
- class disnake.Thumbnail[source]¶
Represents a thumbnail from the Discord Bot UI Kit (v2).
This is only supported as the
accessory
of a section component.Note
The user constructible and usable type to create a thumbnail is
disnake.ui.Thumbnail
.Added in version 2.11.
- media¶
The media item to display. Can be an arbitrary URL or attachment reference (
attachment://<filename>
).- Type:
MediaGallery¶
- class disnake.MediaGallery[source]¶
Represents a media gallery from the Discord Bot UI Kit (v2).
This allows displaying up to 10 images in a gallery.
Note
The user constructible and usable type to create a media gallery is
disnake.ui.MediaGallery
.Added in version 2.11.
- items¶
The images in this gallery.
- Type:
List[
MediaGalleryItem
]
MediaGalleryItem¶
- class disnake.MediaGalleryItem(media, description=None, *, spoiler=False)[source]¶
Represents an item inside a
MediaGallery
.Added in version 2.11.
- Parameters:
media (Union[
str
,Asset
,Attachment
,UnfurledMediaItem
]) – The media item to display. Can be an arbitrary URL or attachment reference (attachment://<filename>
).description (Optional[
str
]) – The item’s description (“alt text”), if any.spoiler (
bool
) – Whether the item is marked as a spoiler. Defaults toFalse
.
FileComponent¶
- class disnake.FileComponent[source]¶
Represents a file component from the Discord Bot UI Kit (v2).
This allows displaying attached files.
Note
The user constructible and usable type to create a file component is
disnake.ui.File
.Added in version 2.11.
- file¶
The file to display. This only supports attachment references (i.e. using the
attachment://<filename>
syntax), not arbitrary URLs.- Type:
- name¶
The name of the file. This is available in objects from the API, and ignored when sending.
- Type:
Optional[
str
]
Separator¶
- class disnake.Separator[source]¶
Represents a separator from the Discord Bot UI Kit (v2).
This allows vertically separating components.
Note
The user constructible and usable type to create a separator is
disnake.ui.Separator
.Added in version 2.11.
- divider¶
Whether the separator should be visible, instead of just being vertical padding/spacing. Defaults to
True
.- Type:
- spacing¶
The size of the separator padding.
- Type:
Container¶
- class disnake.Container[source]¶
Represents a container from the Discord Bot UI Kit (v2).
This is visually similar to
Embed
s, and contains other components.Note
The user constructible and usable type to create a container is
disnake.ui.Container
.Added in version 2.11.
- children¶
The child components in this container.
- Type:
List[Union[
ActionRow
,Section
,TextDisplay
,MediaGallery
,FileComponent
,Separator
]]
- accent_colour¶
The accent colour of the container. An alias exists under
accent_color
.- Type:
Optional[
Colour
]
- id¶
The numeric identifier for the component. This is always present in components received from the API, and unique within a message.
Added in version 2.11.
- Type:
Label¶
- class disnake.Label[source]¶
Represents a label from the Discord Bot UI Kit.
This wraps other components with a label and an optional description, and can only be used in modals.
Added in version 2.11.
Note
The user constructible and usable type to create a label is
disnake.ui.Label
, not this one.- component¶
The component within the label.
- Type:
Union[
TextInput
,StringSelectMenu
]
Enumerations¶
ComponentType¶
- class disnake.ComponentType[source]¶
Represents the type of component.
Added in version 2.0.
- action_row¶
Represents the group component which holds different components in a row.
- button¶
Represents a button component.
- string_select¶
Represents a string select component.
Added in version 2.7.
- select¶
An alias of
string_select
.
- text_input¶
Represents a text input component.
- user_select¶
Represents a user select component.
Added in version 2.7.
- role_select¶
Represents a role select component.
Added in version 2.7.
- mentionable_select¶
Represents a mentionable (user/member/role) select component.
Added in version 2.7.
- channel_select¶
Represents a channel select component.
Added in version 2.7.
- section¶
Represents a Components V2 section component.
Added in version 2.11.
- text_display¶
Represents a Components V2 text display component.
Added in version 2.11.
- thumbnail¶
Represents a Components V2 thumbnail component.
Added in version 2.11.
- media_gallery¶
Represents a Components V2 media gallery component.
Added in version 2.11.
- file¶
Represents a Components V2 file component.
Added in version 2.11.
- separator¶
Represents a Components V2 separator component.
Added in version 2.11.
- container¶
Represents a Components V2 container component.
Added in version 2.11.
- label¶
Represents a label component.
Added in version 2.11.