Enum twilight_model::channel::message::component::Component

source ·
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, SelectMenuType},
        ReactionType,
    },
    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(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

source

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 Clone for Component

source§

fn clone(&self) -> Component

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Component

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Component

source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<ActionRow> for Component

source§

fn from(action_row: ActionRow) -> Self

Converts to this type from the input type.
source§

impl From<Button> for Component

source§

fn from(button: Button) -> Self

Converts to this type from the input type.
source§

impl From<SelectMenu> for Component

source§

fn from(select_menu: SelectMenu) -> Self

Converts to this type from the input type.
source§

impl From<TextInput> for Component

source§

fn from(text_input: TextInput) -> Self

Converts to this type from the input type.
source§

impl Hash for Component

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Component

source§

fn eq(&self, other: &Component) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Component

source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Component

source§

impl StructuralPartialEq for Component

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,