pub struct SlashCommandStringOption { /* private fields */ }Expand description
Builds a string option of a slash command: free text, optionally limited in length, picked from up to 25 choices, or suggested by the app through autocomplete (not together with choices, D-196).
discord.js counterpart: SlashCommandStringOption.
§Examples
use djs_builders::{SlashCommandBuilder, SlashCommandStringOption};
let command = SlashCommandBuilder::new("language", "Sets your language")
.option(
SlashCommandStringOption::new("language", "The language")
.required(true)
.choice("English", "en")
.choice("Polski", "pl"),
)
.option(SlashCommandStringOption::new("note", "Anything else").max_length(200))
.build()
.unwrap();
assert_eq!(command.options.len(), 2);Implementations§
Source§impl SlashCommandStringOption
impl SlashCommandStringOption
Sourcepub fn new(
name: impl Into<CompactString>,
description: impl Into<CompactString>,
) -> Self
pub fn new( name: impl Into<CompactString>, description: impl Into<CompactString>, ) -> Self
Creates an optional option named name (1-32 lower-case letters, numbers, -,
_ or ʼ) and described by description (1-100 characters).
discord.js counterpart: the constructor of the option builders (SlashCommandStringOption, …), with setName.
Sourcepub fn required(self, required: bool) -> Self
pub fn required(self, required: bool) -> Self
Sets whether users must fill the option in (default: no). Required options must come before optional ones.
discord.js counterpart: setRequired.
Sourcepub fn name_localization(
self,
locale: Locale,
name: impl Into<CompactString>,
) -> Self
pub fn name_localization( self, locale: Locale, name: impl Into<CompactString>, ) -> Self
Sets the name shown to users whose Discord language is locale. It follows the same
rules as the name itself.
discord.js counterpart: setNameLocalization.
Sourcepub fn name_localizations<N: Into<CompactString>>(
self,
localizations: impl IntoIterator<Item = (Locale, N)>,
) -> Self
pub fn name_localizations<N: Into<CompactString>>( self, localizations: impl IntoIterator<Item = (Locale, N)>, ) -> Self
Sets several name translations at once, keeping those set before (a locale given again gets the new name).
discord.js counterpart: setNameLocalizations (which replaces them all).
Sourcepub fn description_localization(
self,
locale: Locale,
description: impl Into<CompactString>,
) -> Self
pub fn description_localization( self, locale: Locale, description: impl Into<CompactString>, ) -> Self
Sets the description shown to users whose Discord language is locale (1-100
characters, like the description).
discord.js counterpart: setDescriptionLocalization.
Sourcepub fn description_localizations<D: Into<CompactString>>(
self,
localizations: impl IntoIterator<Item = (Locale, D)>,
) -> Self
pub fn description_localizations<D: Into<CompactString>>( self, localizations: impl IntoIterator<Item = (Locale, D)>, ) -> Self
Sets several description translations at once, keeping those set before.
discord.js counterpart: setDescriptionLocalizations (which replaces them all).
Sourcepub fn build(self) -> Result<CommandOption, ValidationError>
pub fn build(self) -> Result<CommandOption, ValidationError>
Checks the option on its own and returns it as a [CommandOption]; the paths
in a ValidationError start at its fields (name, choices[0].name).
Adding the builder to a command checks it as part of the command instead.
discord.js counterpart: toJSON of the option builders (SlashCommandStringOption, …).
§Errors
The first ValidationError found, as in
SlashCommandBuilder::build.
Sourcepub fn build_unchecked(self) -> CommandOption
pub fn build_unchecked(self) -> CommandOption
Returns the option without any check (D-180).
discord.js counterpart: toJSON of the option builders with validation off (disableValidators).
Source§impl SlashCommandStringOption
impl SlashCommandStringOption
Sourcepub fn choice(
self,
name: impl Into<CompactString>,
value: impl Into<CompactString>,
) -> Self
pub fn choice( self, name: impl Into<CompactString>, value: impl Into<CompactString>, ) -> Self
Adds a choice: name is shown to users (1-100 characters), value is what the app
receives (at most 100 characters). An option has at most 25 choices.
discord.js counterpart: addChoices.
Sourcepub fn choices(
self,
choices: impl IntoIterator<Item = Choice<CompactString>>,
) -> Self
pub fn choices( self, choices: impl IntoIterator<Item = Choice<CompactString>>, ) -> Self
Adds several choices, after those already added — for example with translated names
([Choice::name_localizations]).
discord.js counterpart: addChoices.
Sourcepub fn min_length(self, min_length: u16) -> Self
pub fn min_length(self, min_length: u16) -> Self
Sets the shortest text users may enter (0-6000).
discord.js counterpart: setMinLength.
Sourcepub fn max_length(self, max_length: u16) -> Self
pub fn max_length(self, max_length: u16) -> Self
Sets the longest text users may enter (1-6000, at least the
min_length).
discord.js counterpart: setMaxLength.
Sourcepub fn autocomplete(self, autocomplete: bool) -> Self
pub fn autocomplete(self, autocomplete: bool) -> Self
Sets whether the app suggests values as users type, through autocomplete interactions (not together with choices).
discord.js counterpart: setAutocomplete.