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
impl StringSelectMenuBuilder
Sourcepub fn new(custom_id: impl Into<CompactString>) -> Self
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(…).
Sourcepub fn option(
self,
label: impl Into<CompactString>,
value: impl Into<CompactString>,
) -> Self
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 }).
Sourcepub fn option_with(self, option: StringSelectMenuOptionBuilder) -> Self
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()…).
Sourcepub fn options<O: Into<SelectOption>>(
self,
options: impl IntoIterator<Item = O>,
) -> Self
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
impl StringSelectMenuBuilder
Sourcepub fn placeholder(self, placeholder: impl Into<CompactString>) -> Self
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.
Sourcepub fn min_values(self, min_values: u8) -> Self
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.
Sourcepub fn max_values(self, max_values: u8) -> Self
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.
Sourcepub fn disabled(self, disabled: bool) -> Self
pub fn disabled(self, disabled: bool) -> Self
Sets whether the menu is greyed out (messages only; modals reject it).
discord.js counterpart: setDisabled.
Sourcepub fn required(self, required: bool) -> Self
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.
Sourcepub fn id(self, id: i32) -> Self
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.
Sourcepub fn build(self) -> Result<Component, ValidationError>
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).
Sourcepub fn build_unchecked(self) -> Component
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).