pub enum Component {
ActionRow(ActionRow),
Button(Button),
SelectMenu(SelectMenu),
TextInput(TextInput),
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 {
components: Vec::from([Component::Button(Button {
custom_id: Some("click_one".to_owned()),
disabled: false,
emoji: None,
label: Some("Click me!".to_owned()),
style: ButtonStyle::Primary,
url: None,
})]),
});
Select menu
use twilight_model::{
channel::message::{
component::{ActionRow, Component, SelectMenu, SelectMenuOption},
ReactionType,
},
id::Id,
};
Component::ActionRow(ActionRow {
components: vec![Component::SelectMenu(SelectMenu {
custom_id: "class_select_1".to_owned(),
disabled: false,
max_values: Some(3),
min_values: Some(1),
options: Vec::from([
SelectMenuOption {
default: false,
emoji: Some(ReactionType::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(ReactionType::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(ReactionType::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()),
})],
});
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.
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 {
custom_id: None,
disabled: false,
emoji: None,
label: Some("ping".to_owned()),
style: ButtonStyle::Primary,
url: None,
});
assert_eq!(ComponentType::Button, component.kind());
Trait Implementations§
source§impl<'de> Deserialize<'de> for Component
impl<'de> Deserialize<'de> for Component
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
source§impl From<SelectMenu> for Component
impl From<SelectMenu> for Component
source§fn from(select_menu: SelectMenu) -> Self
fn from(select_menu: SelectMenu) -> Self
Converts to this type from the input type.