pub enum Component {
Show 14 variants
ActionRow(ActionRow),
Button(Button),
SelectMenu(SelectMenu),
TextInput(TextInput),
TextDisplay(TextDisplay),
MediaGallery(MediaGallery),
Separator(Separator),
File(FileDisplay),
Section(Section),
Container(Container),
Thumbnail(Thumbnail),
Label(Label),
FileUpload(FileUpload),
Unknown(u8),
}Expand description
Interactive message element.
Must be either a top level ActionRow or nested inside one.
§Examples
§Button
use twilight_model::channel::message::component::{ActionRow, Button, ButtonStyle, Component};
Component::ActionRow(ActionRow {
id: None,
components: Vec::from([Component::Button(Button {
id: None,
custom_id: Some("click_one".to_owned()),
disabled: false,
emoji: None,
label: Some("Click me!".to_owned()),
style: ButtonStyle::Primary,
url: None,
sku_id: None,
})]),
});§Select menu
use twilight_model::{
channel::message::{
EmojiReactionType,
component::{ActionRow, Component, SelectMenu, SelectMenuOption, SelectMenuType},
},
id::Id,
};
Component::ActionRow(ActionRow {
id: None,
components: vec![Component::SelectMenu(SelectMenu {
id: None,
channel_types: None,
custom_id: "class_select_1".to_owned(),
default_values: None,
disabled: false,
kind: SelectMenuType::Text,
max_values: Some(3),
min_values: Some(1),
options: Some(Vec::from([
SelectMenuOption {
default: false,
emoji: Some(EmojiReactionType::Custom {
animated: false,
id: Id::new(625891304148303894),
name: Some("rogue".to_owned()),
}),
description: Some("Sneak n stab".to_owned()),
label: "Rogue".to_owned(),
value: "rogue".to_owned(),
},
SelectMenuOption {
default: false,
emoji: Some(EmojiReactionType::Custom {
animated: false,
id: Id::new(625891304081063986),
name: Some("mage".to_owned()),
}),
description: Some("Turn 'em into a sheep".to_owned()),
label: "Mage".to_owned(),
value: "mage".to_owned(),
},
SelectMenuOption {
default: false,
emoji: Some(EmojiReactionType::Custom {
animated: false,
id: Id::new(625891303795982337),
name: Some("priest".to_owned()),
}),
description: Some("You get heals when I'm done doing damage".to_owned()),
label: "Priest".to_owned(),
value: "priest".to_owned(),
},
])),
placeholder: Some("Choose a class".to_owned()),
required: None,
})],
});Variants§
ActionRow(ActionRow)
Top level, non-interactive container of other (non action row) components.
Button(Button)
Clickable item that renders below messages.
SelectMenu(SelectMenu)
Dropdown-style item that renders below messages.
TextInput(TextInput)
Pop-up item that renders on modals.
TextDisplay(TextDisplay)
Markdown text.
MediaGallery(MediaGallery)
Display images and other media.
Separator(Separator)
Component to add vertical padding between other components.
File(FileDisplay)
Displays an attached file.
Section(Section)
Container to display text alongside an accessory component.
Container(Container)
Container that visually groups a set of components.
Thumbnail(Thumbnail)
Small image that can be used as an accessory.
Label(Label)
Wrapper for modal components providing a label and an optional description.
FileUpload(FileUpload)
Allows uploading files in a modal.
Unknown(u8)
Variant value is unknown to the library.
Implementations§
Source§impl Component
impl Component
Sourcepub const fn kind(&self) -> ComponentType
pub const fn kind(&self) -> ComponentType
Type of component that this is.
use twilight_model::channel::message::component::{
Button, ButtonStyle, Component, ComponentType,
};
let component = Component::Button(Button {
id: None,
custom_id: None,
disabled: false,
emoji: None,
label: Some("ping".to_owned()),
style: ButtonStyle::Primary,
url: None,
sku_id: None,
});
assert_eq!(ComponentType::Button, component.kind());Sourcepub const fn component_count(&self) -> usize
pub const fn component_count(&self) -> usize
Get the amount of components a component should count as.