pub struct SlashCommandSubcommandBuilder { /* private fields */ }Expand description
Builds a subcommand
of a slash command (/command subcommand), with its own options.
Add it with SlashCommandBuilder::subcommand or
SlashCommandSubcommandGroupBuilder::subcommand. build checks it on its
own, with paths starting at its fields.
discord.js counterpart: SlashCommandSubcommandBuilder.
§Examples
use djs_builders::{SlashCommandBuilder, SlashCommandStringOption, SlashCommandSubcommandBuilder};
let tag = SlashCommandBuilder::new("tag", "Manages tags")
.subcommand(
SlashCommandSubcommandBuilder::new("show", "Shows a tag")
.option(SlashCommandStringOption::new("name", "The tag").required(true)),
)
.subcommand(SlashCommandSubcommandBuilder::new("list", "Lists every tag"))
.build()
.unwrap();
assert_eq!(tag.options[1].name(), "list");Implementations§
Source§impl SlashCommandSubcommandBuilder
impl SlashCommandSubcommandBuilder
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 a subcommand named name (1-32 lower-case letters, numbers, -, _ or ʼ)
and described by description (1-100 characters).
discord.js counterpart: new SlashCommandSubcommandBuilder().setName(name).
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 option(self, option: impl Into<CommandOption>) -> Self
pub fn option(self, option: impl Into<CommandOption>) -> Self
Adds an option of the subcommand (at most 25; not a subcommand or group).
discord.js counterpart: addStringOption, addIntegerOption, … (one per type).
Sourcepub fn build(self) -> Result<CommandOption, ValidationError>
pub fn build(self) -> Result<CommandOption, ValidationError>
Checks the subcommand on its own and returns it as a [CommandOption].
discord.js counterpart: SlashCommandSubcommandBuilder#toJSON.
§Errors
The first ValidationError found, as in SlashCommandBuilder::build (without the
8000-character total, which applies to the whole command).
Sourcepub fn build_unchecked(self) -> CommandOption
pub fn build_unchecked(self) -> CommandOption
Returns the subcommand without any check (D-180).
discord.js counterpart: SlashCommandSubcommandBuilder#toJSON with validation off (disableValidators).