pub struct SlashCommandIntegerOption { /* private fields */ }Expand description
Builds an integer option of a slash command: a whole number between -(2^53 − 1) and 2^53 − 1, optionally bounded, picked from up to 25 choices, or suggested through autocomplete.
discord.js counterpart: SlashCommandIntegerOption.
§Examples
use djs_builders::{SlashCommandBuilder, SlashCommandIntegerOption};
let command = SlashCommandBuilder::new("roll", "Rolls a die")
.option(SlashCommandIntegerOption::new("sides", "How many sides").min_value(2).max_value(100))
.build()
.unwrap();
assert_eq!(command.options[0].name(), "sides");Implementations§
Source§impl SlashCommandIntegerOption
impl SlashCommandIntegerOption
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 SlashCommandIntegerOption
impl SlashCommandIntegerOption
Sourcepub fn choice(self, name: impl Into<CompactString>, value: i64) -> Self
pub fn choice(self, name: impl Into<CompactString>, value: i64) -> Self
Adds a choice: name is shown to users (1-100 characters), value is what the app
receives. An option has at most 25 choices.
discord.js counterpart: addChoices.
Sourcepub fn choices(self, choices: impl IntoIterator<Item = Choice<i64>>) -> Self
pub fn choices(self, choices: impl IntoIterator<Item = Choice<i64>>) -> Self
Adds several choices, after those already added.
discord.js counterpart: addChoices.
Sourcepub fn min_value(self, min_value: i64) -> Self
pub fn min_value(self, min_value: i64) -> Self
Sets the smallest value users may enter.
discord.js counterpart: setMinValue.
Sourcepub fn max_value(self, max_value: i64) -> Self
pub fn max_value(self, max_value: i64) -> Self
Sets the largest value users may enter (at least the min_value).
discord.js counterpart: setMaxValue.
Sourcepub fn autocomplete(self, autocomplete: bool) -> Self
pub fn autocomplete(self, autocomplete: bool) -> Self
Sets whether the app suggests values as users type (not together with choices).
discord.js counterpart: setAutocomplete.