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§
- Action
Row - An action row: up to 5 buttons or a single select menu, at the top level of a message or in a container.
- Auto
Populated Select - A select menu whose options Discord fills in: the user,
role and
mentionable
selects share this structure (see
ChannelSelectfor channels). - Channel
Select - A channel select: a menu of channels that Discord fills in.
- Checkbox
- A single checkbox in a modal: a yes/no choice.
- Checkbox
Group - 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.
- Content
Scan Metadata - The results of Discord’s content scanning
of an
UnfurledMediaItem. - Content
Scan Metadata Flags - Flags of content scan metadata.
- File
- A file: an attached file shown in the message.
- File
Upload - A file upload in a modal (inside a label).
- Group
Option - An option of a
RadioGrouporCheckboxGroup(the docs define two identical structures). - Interactive
Button - A button that sends an interaction with its
custom_idwhen clicked (stylesPrimarytoDanger). - 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).
- Link
Button - A button that opens a
url(styleLink). - Media
Gallery - A media gallery: 1-10 images or videos in a grid.
- Media
Gallery Item - An item of a media gallery.
- Premium
Button - 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. - Radio
Group - 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.
- Select
Default Value - An entity selected by default in an auto-populated select menu.
- Select
Option - An option of a string select.
- Separator
- A separator: vertical space between components, with an optional line. Messages only.
- String
Select - A string select: a menu of developer-defined options (in an action row in messages, in a label in modals).
- Text
Display - A text display: markdown text, like a message’s content (messages and modals).
- Text
Input - A text input in a modal (inside a label).
- Thumbnail
- A thumbnail: a small image, used as a section accessory.
- Unfurled
Media Item - An unfurled media item: a URL or an uploaded attachment that Discord resolves into media.
- Unfurled
Media Item Flags - Flags of an unfurled media item.
- Unknown
Button - A button whose style this version of the library does not know about; every button field is kept.
- Unknown
Component - 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).
- Button
Style - The style of a button.
- Component
- A component of a message or modal (D-065).
- Component
Type - The type of a component.
- Loading
State - Whether Discord could load an
UnfurledMediaItem. - Select
Default Value Type - What a
SelectDefaultValuerefers to. - Separator
Spacing - The space a separator adds.
- Text
Input Style - The style of a text input.