Skip to main content

StringSelectMenuBuilder

Struct StringSelectMenuBuilder 

Source
pub struct StringSelectMenuBuilder { /* private fields */ }
Expand description

Builds a string select menu: a drop-down of up to 25 options you define, sending the chosen values to your app.

Add plain options with option and detailed ones with option_with (D-203). build checks what Discord checks (D-200): 1-25 options and at least max_values of them, labels of 1-100 characters, unique values of 1-100 characters, descriptions of at most 100.

discord.js counterpart: StringSelectMenuBuilder.

§Examples

use djs_builders::{ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder};

let menu = StringSelectMenuBuilder::new("color")
    .placeholder("Pick colors")
    .option("Red", "red")
    .option("Green", "green")
    .option_with(
        StringSelectMenuOptionBuilder::new("Blue", "blue")
            .description("Like the sky")
            .default(true),
    )
    .max_values(2);
let row = ActionRowBuilder::new().component(menu).build().unwrap();
assert_eq!(row.children().len(), 1);

Implementations§

Source§

impl StringSelectMenuBuilder

Source

pub fn new(custom_id: impl Into<CompactString>) -> Self

Creates a menu without options, sending custom_id (1-100 characters) to your app.

discord.js counterpart: new StringSelectMenuBuilder().setCustomId(…).

Source

pub fn option( self, label: impl Into<CompactString>, value: impl Into<CompactString>, ) -> Self

Adds an option showing label (1-100 characters) and sending value (1-100 characters, unique in the menu).

discord.js counterpart: addOptions({ label, value }).

Source

pub fn option_with(self, option: StringSelectMenuOptionBuilder) -> Self

Adds an option with a description, an emoji or selected by default.

discord.js counterpart: addOptions(new StringSelectMenuOptionBuilder()…).

Source

pub fn options<O: Into<SelectOption>>( self, options: impl IntoIterator<Item = O>, ) -> Self

Adds several options: StringSelectMenuOptionBuilders or djs-model [SelectOption]s.

discord.js counterpart: addOptions.

Source§

impl StringSelectMenuBuilder

Source

pub fn placeholder(self, placeholder: impl Into<CompactString>) -> Self

Sets the text shown while nothing is selected (at most 150 characters).

discord.js counterpart: setPlaceholder.

Source

pub fn min_values(self, min_values: u8) -> Self

Sets how many items must be chosen at least (0-25; Discord’s default: 1).

discord.js counterpart: setMinValues.

Source

pub fn max_values(self, max_values: u8) -> Self

Sets how many items can be chosen at most (1-25, at least min_values; Discord’s default: 1).

discord.js counterpart: setMaxValues.

Source

pub fn disabled(self, disabled: bool) -> Self

Sets whether the menu is greyed out (messages only; modals reject it).

discord.js counterpart: setDisabled.

Source

pub fn required(self, required: bool) -> Self

Sets whether an answer is required when the menu is in a modal (default: yes; ignored in messages).

discord.js counterpart: setRequired.

Source

pub fn id(self, id: i32) -> Self

Sets the component’s numeric identifier (Discord generates one otherwise); it must be unique in the message or modal.

discord.js counterpart: setId.

Source

pub fn build(self) -> Result<Component, ValidationError>

Checks the menu and returns it as a [Component].

discord.js counterpart: toJSON of the select menu builders.

§Errors

The first ValidationError found: the custom_id (1-100 characters), the placeholder (at most 150), min_values (0-25) and max_values (1-25, at least min_values), then what the menu offers (see the type docs).

Source

pub fn build_unchecked(self) -> Component

Returns the menu without any check (D-180).

discord.js counterpart: toJSON of the select menu builders with validation off (disableValidators).

Trait Implementations§

Source§

impl Clone for StringSelectMenuBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for StringSelectMenuBuilder

Source§

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

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

impl Eq for StringSelectMenuBuilder

Source§

impl From<StringSelectMenuBuilder> for Component

Source§

fn from(menu: StringSelectMenuBuilder) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for StringSelectMenuBuilder

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for StringSelectMenuBuilder

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.