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:
- id¶
The numeric identifier for the component. Must be unique within a message or modal. This is always present in components received from the API. If set to
0(the default) when sending a component, the API will assign sequential identifiers to the components in the message or modal.Added in version 2.11.
- Type:
ActionRow¶
- class disnake.ActionRow[source]¶
Represents an action row.
This is a component that holds up to 5 children components in a row.
This inherits from
Component.Added in version 2.0.
- children¶
The children components that this holds, if any.
- Type:
- id¶
The numeric identifier for the component. Must be unique within a message. This is always present in components received from the API. If set to
0(the default) when sending a component, the API will assign sequential identifiers to the components in the message.Added in version 2.11.
- Type:
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.
- emoji¶
The emoji of the option, if available.
- Type:
str|Emoji|PartialEmoji|None
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
typeattribute, 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:
- id¶
The numeric identifier for the component. Must be unique within a message. This is always present in components received from the API. If set to
0(the default) when sending a component, the API will assign sequential identifiers to the components in the message.Added in version 2.11.
- Type:
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.
- id¶
The numeric identifier for the component. Must be unique within a message. This is always present in components received from the API. If set to
0(the default) when sending a component, the API will assign sequential identifiers to the components in the message.Added in version 2.11.
- Type:
UnfurledMediaItem¶
Thumbnail¶
- class disnake.Thumbnail[source]¶
Represents a thumbnail from the Discord Bot UI Kit (v2).
This is only supported as the
accessoryof 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:
- id¶
The numeric identifier for the component. Must be unique within a message. This is always present in components received from the API. If set to
0(the default) when sending a component, the API will assign sequential identifiers to the components in the message.Added in version 2.11.
- 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:
- id¶
The numeric identifier for the component. Must be unique within a message. This is always present in components received from the API. If set to
0(the default) when sending a component, the API will assign sequential identifiers to the components in the message.Added in version 2.11.
- Type:
MediaGalleryItem¶
- class disnake.MediaGalleryItem(media, description=None, *, spoiler=False)[source]¶
Represents an item inside a
MediaGallery.Added in version 2.11.
- Parameters:
media (
str|Asset|Attachment|UnfurledMediaItem) – The media item to display. Can be an arbitrary URL or attachment reference (attachment://<filename>).description (
str|None) – 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.
- size¶
The size of the file. This is available in objects from the API, and ignored when sending.
- id¶
The numeric identifier for the component. Must be unique within a message. This is always present in components received from the API. If set to
0(the default) when sending a component, the API will assign sequential identifiers to the components in the message.Added in version 2.11.
- Type:
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:
- id¶
The numeric identifier for the component. Must be unique within a message. This is always present in components received from the API. If set to
0(the default) when sending a component, the API will assign sequential identifiers to the components in the message.Added in version 2.11.
- Type:
Container¶
- class disnake.Container[source]¶
Represents a container from the Discord Bot UI Kit (v2).
This is visually similar to
Embeds, 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[ActionRow|Section|TextDisplay|MediaGallery|FileComponent|Separator]
- accent_colour¶
The accent colour of the container. An alias exists under
accent_color.
- id¶
The numeric identifier for the component. Must be unique within a message. This is always present in components received from the API. If set to
0(the default) when sending a component, the API will assign sequential identifiers to the components in the 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:
TextInput|FileUpload|BaseSelectMenu|RadioGroup|CheckboxGroup|Checkbox
FileUpload¶
- class disnake.FileUpload[source]¶
Represents a file upload component from the Discord Bot UI Kit.
This allows you to receive files from users, and can only be used in modals.
Note
The user constructible and usable type to create a file upload is
disnake.ui.FileUpload.Added in version 2.12.
- min_values¶
The minimum number of files that must be uploaded. Defaults to 1 and must be between 0 and 10.
- Type:
- max_values¶
The maximum number of files that must be uploaded. Defaults to 1 and must be between 1 and 10.
- Type:
GroupOption¶
- class disnake.GroupOption[source]¶
Represents an option inside a
RadioGrouporCheckboxGroup.Added in version 2.12.
- Parameters:
label (
str) – The label of the option. This is displayed to users. Can be up to 100 characters.value (
str) – The value of the option. This is not displayed to users. If not provided when constructed then it defaults to the label. Can be up to 100 characters.description (
str|None) – The options’s description, if any.default (
bool) – Whether this option is selected by default. Defaults toFalse.
RadioGroup¶
- class disnake.RadioGroup[source]¶
Represents a component containing radio buttons/options from the Discord Bot UI Kit.
This requires users to select exactly one out of the given options, and can only be used in modals.
Note
The user constructible and usable type to create a radio group is
disnake.ui.RadioGroup.Added in version 2.12.
- options¶
A list of options that can be selected in this group (2-10).
- Type:
CheckboxGroup¶
- class disnake.CheckboxGroup[source]¶
Represents a component containing checkboxes from the Discord Bot UI Kit.
This requires users to select up to 10 checkboxes, and can only be used in modals. For single checkboxes, see
Checkbox.Note
The user constructible and usable type to create a checkbox group is
disnake.ui.CheckboxGroup.Added in version 2.12.
- options¶
A list of options that can be selected in this group (1-10).
- Type:
- min_values¶
The minimum number of options that must be selected in this group. Defaults to 1 and must be between 0 and 10.
- Type:
- max_values¶
The maximum number of options that must be selected in this group. Must be between 1 and 10. If set to
None(the default), all options can be selected.
- required¶
Whether selecting an option in this checkbox group is required. Defaults to
True.- Type:
Checkbox¶
- class disnake.Checkbox[source]¶
Represents a single checkbox component from the Discord Bot UI Kit.
This can only be used in modals. For a group of multiple checkboxes, see
CheckboxGroup.Note
The user constructible and usable type to create a checkbox is
disnake.ui.Checkbox.Added in version 2.12.
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.
- file_upload¶
Represents a file upload component.
Added in version 2.12.
- radio_group¶
Represents a radio group component.
Added in version 2.12.
- checkbox_group¶
Represents a checkbox group component.
Added in version 2.12.
- checkbox¶
Represents a checkbox component.
Added in version 2.12.