Skip to main content

Module component

Module component 

Source
Expand description

Components: interactive and layout elements of messages and modals (buttons, select menus, text inputs, and the Components V2 layout and content elements).

Every component is a variant of Component (D-065), with one precise struct per type (D-063). Children are Vec<Component>, so any known component decodes in any position. Which components may be nested where is described on each type; builders validate it when sending (Phase 6).

Components are also sent. The structs are #[non_exhaustive], so they are created with their new constructors (taking the required fields) and the optional fields are set afterwards:

use djs_model::component::{ActionRow, ButtonStyle, Component, InteractiveButton};

let mut button = InteractiveButton::new(ButtonStyle::Primary, "confirm");
button.label = Some("Confirm".into());
let row = ActionRow::new(vec![Component::from(button)]);
assert_eq!(
    serde_json::to_string(&Component::from(row)).unwrap(),
    r#"{"type":1,"components":[{"type":2,"style":1,"custom_id":"confirm","label":"Confirm"}]}"#
);

Structs§

ActionRow
An action row: up to 5 buttons or a single select menu, at the top level of a message or in a container.
AutoPopulatedSelect
A select menu whose options Discord fills in: the user, role and mentionable selects share this structure (see ChannelSelect for channels).
ChannelSelect
A channel select: a menu of channels that Discord fills in.
Checkbox
A single checkbox in a modal: a yes/no choice.
CheckboxGroup
A checkbox group in a modal: any number of 1-10 options.
Container
A container: a visually grouped box of components with an optional accent color, like an embed. Messages only.
ContentScanMetadata
The results of Discord’s content scanning of an UnfurledMediaItem.
ContentScanMetadataFlags
Flags of content scan metadata.
File
A file: an attached file shown in the message.
FileUpload
A file upload in a modal (inside a label).
GroupOption
An option of a RadioGroup or CheckboxGroup (the docs define two identical structures).
InteractiveButton
A button that sends an interaction with its custom_id when clicked (styles Primary to Danger).
Label
A label: a title and description for one input in a modal (text input, select menu, file upload, radio group, checkbox group or checkbox).
LinkButton
A button that opens a url (style Link).
MediaGallery
A media gallery: 1-10 images or videos in a grid.
MediaGalleryItem
An item of a media gallery.
PremiumButton
A button that starts the purchase of an SKU (style Premium). It shows the SKU’s name and price; it cannot have a label or emoji.
RadioGroup
A radio group in a modal: exactly one of 2-10 options.
Section
A section: 1-3 text displays next to an accessory (button or thumbnail). Messages only.
SelectDefaultValue
An entity selected by default in an auto-populated select menu.
SelectOption
An option of a string select.
Separator
A separator: vertical space between components, with an optional line. Messages only.
StringSelect
A string select: a menu of developer-defined options (in an action row in messages, in a label in modals).
TextDisplay
A text display: markdown text, like a message’s content (messages and modals).
TextInput
A text input in a modal (inside a label).
Thumbnail
A thumbnail: a small image, used as a section accessory.
UnfurledMediaItem
An unfurled media item: a URL or an uploaded attachment that Discord resolves into media.
UnfurledMediaItemFlags
Flags of an unfurled media item.
UnknownButton
A button whose style this version of the library does not know about; every button field is kept.
UnknownComponent
A component of a type this version of the library does not know about. Only the fields every component has are kept.

Enums§

Button
A button, in an action row or as a section accessory (messages only).
ButtonStyle
The style of a button.
Component
A component of a message or modal (D-065).
ComponentType
The type of a component.
LoadingState
Whether Discord could load an UnfurledMediaItem.
SelectDefaultValueType
What a SelectDefaultValue refers to.
SeparatorSpacing
The space a separator adds.
TextInputStyle
The style of a text input.