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,
sku_id: None,
})]),
});
§Select menu
use twilight_model::{
channel::message::{
component::{ActionRow, Component, SelectMenu, SelectMenuOption, SelectMenuType},
EmojiReactionType,
},
id::Id,
};
Component::ActionRow(ActionRow {
components: vec![Component::SelectMenu(SelectMenu {
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()),
})],
});
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,
sku_id: 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.
impl Eq for Component
impl StructuralPartialEq for Component
Auto Trait Implementations§
impl Freeze for Component
impl RefUnwindSafe for Component
impl Send for Component
impl Sync for Component
impl Unpin for Component
impl UnwindSafe for Component
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)