Class SubcommandData
java.lang.Object
net.dv8tion.jda.api.interactions.commands.build.SubcommandData
- All Implemented Interfaces:
SerializableData
Builder for a Slash-Command subcommand.
-
Constructor Summary
ConstructorsConstructorDescriptionSubcommandData(String name, String description) Create a subcommand builder. -
Method Summary
Modifier and TypeMethodDescriptionaddOption(OptionType type, String name, String description) Adds an option to this subcommand.addOption(OptionType type, String name, String description, boolean required) Adds an option to this subcommand.addOption(OptionType type, String name, String description, boolean required, boolean autoComplete) Adds an option to this subcommand.addOptions(Collection<? extends OptionData> options) Adds up to 25 options to this subcommand.addOptions(OptionData... options) Adds up to 25 options to this subcommand.static SubcommandDatafromData(DataObject json) Parses the provided serialization back into an SubcommandData instance.static SubcommandDatafromSubcommand(Command.Subcommand subcommand) Converts the providedCommand.Subcommandinto a SubCommandData instance.The configured descriptionThe localizations of this subcommand's description forvarious languages.getName()The configured nameThe localizations of this subcommand's name forvarious languages.@Unmodifiable List<OptionData>The options for this command.booleanremoveOptionByName(String name) Removes options by the provided name.booleanremoveOptions(Predicate<? super OptionData> condition) Removes all options that evaluate totrueunder the providedcondition.setDescription(String description) Configure the descriptionsetDescriptionLocalization(DiscordLocale locale, String description) Sets alanguage-specificlocalization of this subcommand's description.Sets multiplelanguage-specificlocalizations of this subcommand's description.Configure the namesetNameLocalization(DiscordLocale locale, String name) Sets alanguage-specificlocalization of this subcommand's name.Sets multiplelanguage-specificlocalizations of this subcommand's name.toData()SerializedDataObjectfor this object.
-
Constructor Details
-
SubcommandData
Create a subcommand builder.- Parameters:
name- The subcommand name, 1-32 lowercase alphanumeric charactersdescription- The subcommand description, 1-100 characters- Throws:
IllegalArgumentException- If any of the following requirements are not met- The name must be lowercase alphanumeric (with dash), 1-32 characters long
- The description must be 1-100 characters long
-
-
Method Details
-
setName
Configure the name- Parameters:
name- The lowercase alphanumeric (with dash) name, 1-32 characters- Returns:
- The SubcommandData instance, for chaining
- Throws:
IllegalArgumentException- If the name is null, not alphanumeric, or not between 1-32 characters
-
setNameLocalization
@Nonnull public SubcommandData setNameLocalization(@Nonnull DiscordLocale locale, @Nonnull String name) Sets alanguage-specificlocalization of this subcommand's name.- Parameters:
locale- The locale to associate the translated name withname- The translated name to put- Returns:
- This builder instance, for chaining
- Throws:
IllegalArgumentException-- If the locale is null
- If the name is null
- If the locale is
DiscordLocale.UNKNOWN - If the name does not pass the corresponding
name check
-
setNameLocalizations
Sets multiplelanguage-specificlocalizations of this subcommand's name.- Parameters:
map- The map from which to transfer the translated names- Returns:
- This builder instance, for chaining
- Throws:
IllegalArgumentException-- If the map is null
- If the map contains an
DiscordLocale.UNKNOWNkey - If the map contains a name which does not pass the corresponding
name check
-
setDescription
Configure the description- Parameters:
description- The description, 1-100 characters- Returns:
- The SubcommandData instance, for chaining
- Throws:
IllegalArgumentException- If the name is null or not between 1-100 characters
-
setDescriptionLocalization
@Nonnull public SubcommandData setDescriptionLocalization(@Nonnull DiscordLocale locale, @Nonnull String description) Sets alanguage-specificlocalization of this subcommand's description.- Parameters:
locale- The locale to associate the translated description withdescription- The translated description to put- Returns:
- This builder instance, for chaining
- Throws:
IllegalArgumentException-- If the locale is null
- If the description is null
- If the locale is
DiscordLocale.UNKNOWN - If the description does not pass the corresponding
description check
-
setDescriptionLocalizations
Sets multiplelanguage-specificlocalizations of this subcommand's description.- Parameters:
map- The map from which to transfer the translated descriptions- Returns:
- This builder instance, for chaining
- Throws:
IllegalArgumentException-- If the map is null
- If the map contains an
DiscordLocale.UNKNOWNkey - If the map contains a description which does not pass the corresponding
description check
-
removeOptions
Removes all options that evaluate totrueunder the providedcondition.Example: Remove all options
command.removeOptions(option -> true);Example: Remove all options that are required
command.removeOptions(option -> option.isRequired());- Parameters:
condition- The removal condition (must not throw)- Returns:
- True, if any options were removed
- Throws:
IllegalArgumentException- If the condition is null
-
removeOptionByName
Removes options by the provided name.- Parameters:
name- The case-sensitive option name- Returns:
- True, if any options were removed
-
addOptions
Adds up to 25 options to this subcommand.Required options must be added before non-required options!
- Parameters:
options- Theoptionsto add- Returns:
- The SubcommandData instance, for chaining
- Throws:
IllegalArgumentException-- If this option is required and you already added a non-required option.
- If more than 25 options are provided.
- If the option name is not unique
- If null is provided
-
addOptions
Adds up to 25 options to this subcommand.Required options must be added before non-required options!
- Parameters:
options- Theoptionsto add- Returns:
- The SubcommandData instance, for chaining
- Throws:
IllegalArgumentException-- If this option is required and you already added a non-required option.
- If more than 25 options are provided.
- If the option name is not unique
- If null is provided
-
addOption
@Nonnull public SubcommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean required, boolean autoComplete) Adds an option to this subcommand.Required options must be added before non-required options!
- Parameters:
type- TheOptionTypename- The lowercase option name, 1-32 charactersdescription- The option description, 1-100 charactersrequired- Whether this option is required (SeeOptionData.setRequired(boolean))autoComplete- Whether this option supports auto-complete viaCommandAutoCompleteInteractionEvent, only supported for option types whichsupport choices- Returns:
- The SubcommandData instance, for chaining
- Throws:
IllegalArgumentException-- If this option is required and you already added a non-required option.
- If the provided option type does not support auto-complete
- If more than 25 options are provided.
- If the option name is not unique
- If null is provided
-
addOption
@Nonnull public SubcommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean required) Adds an option to this subcommand.Required options must be added before non-required options!
- Parameters:
type- TheOptionTypename- The lowercase option name, 1-32 charactersdescription- The option description, 1-100 charactersrequired- Whether this option is required (SeeOptionData.setRequired(boolean))- Returns:
- The SubcommandData instance, for chaining
- Throws:
IllegalArgumentException-- If this option is required and you already added a non-required option.
- If more than 25 options are provided.
- If the option name is not unique
- If null is provided
-
addOption
@Nonnull public SubcommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description) Adds an option to this subcommand.
The option is set to be non-required! You can useaddOption(OptionType, String, String, boolean)to add a required option instead.Required options must be added before non-required options!
- Parameters:
type- TheOptionTypename- The lowercase option name, 1-32 charactersdescription- The option description, 1-100 characters- Returns:
- The SubcommandData instance, for chaining
- Throws:
IllegalArgumentException-- If this option is required and you already added a non-required option.
- If more than 25 options are provided.
- If the option name is not unique
- If null is provided
-
getOptions
The options for this command.- Returns:
- Immutable list of
OptionData
-
getName
The configured name- Returns:
- The name
-
getNameLocalizations
The localizations of this subcommand's name forvarious languages.- Returns:
- The
LocalizationMapcontaining the mapping fromDiscordLocaleto the localized name
-
getDescription
The configured description- Returns:
- The description
-
getDescriptionLocalizations
The localizations of this subcommand's description forvarious languages.- Returns:
- The
LocalizationMapcontaining the mapping fromDiscordLocaleto the localized description
-
toData
Description copied from interface:SerializableDataSerializedDataObjectfor this object.- Specified by:
toDatain interfaceSerializableData- Returns:
DataObject
-
fromData
Parses the provided serialization back into an SubcommandData instance.
This is the reverse function fortoData().- Parameters:
json- The serializedDataObjectrepresenting the subcommand- Returns:
- The parsed SubcommandData instance, which can be further configured through setters
- Throws:
ParsingException- If the serialized object is missing required fieldsIllegalArgumentException- If any of the values are failing the respective checks such as length
-
fromSubcommand
Converts the providedCommand.Subcommandinto a SubCommandData instance.- Parameters:
subcommand- The subcommand to convert- Returns:
- An instance of SubCommandData
- Throws:
IllegalArgumentException- If null is provided or the subcommand has illegal configuration
-