Interface SlashCommandData
- All Superinterfaces:
CommandData,SerializableData
- All Known Subinterfaces:
CommandCreateAction
Extension of
CommandData which allows setting slash-command specific settings such as options and subcommands.-
Field Summary
Fields inherited from interface net.dv8tion.jda.api.interactions.commands.build.CommandData
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH -
Method Summary
Modifier and TypeMethodDescriptiondefault SlashCommandDataaddOption(OptionType type, String name, String description) Adds an option to this command.default SlashCommandDataaddOption(OptionType type, String name, String description, boolean required) Adds an option to this command.default SlashCommandDataaddOption(OptionType type, String name, String description, boolean required, boolean autoComplete) Adds an option to this command.default SlashCommandDataaddOptions(Collection<? extends OptionData> options) Adds up to 25 options to this command.addOptions(OptionData... options) Adds up to 25 options to this command.default SlashCommandDataaddSubcommandGroups(Collection<? extends SubcommandGroupData> groups) Add up to 25Subcommand-Groupsto this command.addSubcommandGroups(SubcommandGroupData... groups) Add up to 25Subcommand-Groupsto this command.default SlashCommandDataaddSubcommands(Collection<? extends SubcommandData> subcommands) Add up to 25Subcommandsto this command.addSubcommands(SubcommandData... subcommands) Add up to 25Subcommandsto this command.static SlashCommandDatafromCommand(Command command) Converts the providedCommandinto a SlashCommandData instance.static SlashCommandDatafromData(DataObject object) Parses the provided serialization back into a SlashCommandData instance.The configured descriptionThe localizations of this command's description forvarious languages.The options for this command.TheSubcommand Groupsin this command.TheSubcommandsin this command.setDefaultPermissions(DefaultMemberPermissions permission) Sets thePermissionsthat a user must have in a specific channel to be able to use this command.setDescription(String description) Configure the descriptionsetDescriptionLocalization(DiscordLocale locale, String description) Sets alanguage-specificlocalizations of this command's description.Sets multiplelanguage-specificlocalizations of this command's description.setGuildOnly(boolean guildOnly) Sets whether this command is only usable in a guild (Default: false).setLocalizationFunction(LocalizationFunction localizationFunction) Sets theLocalizationFunctionfor this command
This enables you to have the entirety of this command to be localized.Configure the command name.setNameLocalization(DiscordLocale locale, String name) Sets alanguage-specificlocalization of this command's name.Sets multiplelanguage-specificlocalizations of this command's name.Methods inherited from interface net.dv8tion.jda.api.interactions.commands.build.CommandData
getDefaultPermissions, getName, getNameLocalizations, getType, isGuildOnlyMethods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toData
-
Method Details
-
setLocalizationFunction
@Nonnull SlashCommandData setLocalizationFunction(@Nonnull LocalizationFunction localizationFunction) Description copied from interface:CommandDataSets theLocalizationFunctionfor this command
This enables you to have the entirety of this command to be localized.- Specified by:
setLocalizationFunctionin interfaceCommandData- Parameters:
localizationFunction- The localization function- Returns:
- The builder instance, for chaining
-
setName
Description copied from interface:CommandDataConfigure the command name.- Specified by:
setNamein interfaceCommandData- Parameters:
name- The name, 1-32 characters (lowercase and alphanumeric forCommand.Type.SLASH)- Returns:
- The builder instance, for chaining
-
setNameLocalization
Description copied from interface:CommandDataSets alanguage-specificlocalization of this command's name.- Specified by:
setNameLocalizationin interfaceCommandData- Parameters:
locale- The locale to associate the translated name withname- The translated name to put- Returns:
- This builder instance, for chaining
-
setNameLocalizations
Description copied from interface:CommandDataSets multiplelanguage-specificlocalizations of this command's name.- Specified by:
setNameLocalizationsin interfaceCommandData- Parameters:
map- The map from which to transfer the translated names- Returns:
- This builder instance, for chaining
-
setDefaultPermissions
Description copied from interface:CommandDataSets thePermissionsthat a user must have in a specific channel to be able to use this command.
By default, everyone can use this command (DefaultMemberPermissions.ENABLED). Additionally, a command can be disabled for everyone but admins viaDefaultMemberPermissions.DISABLED.These configurations can be overwritten by moderators in each guild. See
Command.retrievePrivileges(net.dv8tion.jda.api.entities.Guild)to get moderator defined overrides.- Specified by:
setDefaultPermissionsin interfaceCommandData- Parameters:
permission-DefaultMemberPermissionsrepresenting the default permissions of this command.- Returns:
- The builder instance, for chaining
- See Also:
-
setGuildOnly
Description copied from interface:CommandDataSets whether this command is only usable in a guild (Default: false).
This only has an effect if this command is registered globally.- Specified by:
setGuildOnlyin interfaceCommandData- Parameters:
guildOnly- Whether to restrict this command to guilds- Returns:
- The builder instance, for chaining
-
setDescription
Configure the description- Parameters:
description- The description, 1-100 characters- Returns:
- The builder, for chaining
- Throws:
IllegalArgumentException- If the name is null or not between 1-100 characters
-
setDescriptionLocalization
@Nonnull SlashCommandData setDescriptionLocalization(@Nonnull DiscordLocale locale, @Nonnull String description) Sets alanguage-specificlocalizations of this command'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 command'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
-
getDescription
The configured description- Returns:
- The description
-
getDescriptionLocalizations
The localizations of this command's description forvarious languages.- Returns:
- The
LocalizationMapcontaining the mapping fromDiscordLocaleto the localized description
-
getSubcommands
TheSubcommandsin this command.
These subcommand instances are reconstructed, which means that any modifications will not be reflected in the backing state.- Returns:
- Immutable list of
SubcommandData
-
getSubcommandGroups
TheSubcommand Groupsin this command.
These subcommand group instances are reconstructed, which means that any modifications will not be reflected in the backing state.- Returns:
- Immutable list of
SubcommandGroupData
-
getOptions
The options for this command.
These option instances are reconstructed, which means that any modifications will not be reflected in the backing state.- Returns:
- Immutable list of
OptionData
-
addOptions
Adds up to 25 options to this command.Required options must be added before non-required options!
- Parameters:
options- TheOptionsto add- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException-- If you try to mix subcommands/options/groups in one command.
- If the option type is
OptionType.SUB_COMMANDorOptionType.SUB_COMMAND_GROUP. - 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 command.Required options must be added before non-required options!
- Parameters:
options- TheOptionsto add- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException-- If you try to mix subcommands/options/groups in one command.
- If the option type is
OptionType.SUB_COMMANDorOptionType.SUB_COMMAND_GROUP. - 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 default SlashCommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean required, boolean autoComplete) Adds an option to this command.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 builder instance, for chaining
- Throws:
IllegalArgumentException-- If you try to mix subcommands/options/groups in one command.
- If the option type is
UNKNOWN. - If the option type is
OptionType.SUB_COMMANDorOptionType.SUB_COMMAND_GROUP. - If the provided option type does not support auto-complete
- 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 default SlashCommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean required) Adds an option to this command.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 builder instance, for chaining
- Throws:
IllegalArgumentException-- If you try to mix subcommands/options/groups in one command.
- If the option type is
UNKNOWN. - If the option type is
OptionType.SUB_COMMANDorOptionType.SUB_COMMAND_GROUP. - 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 default SlashCommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description) Adds an option to this command.
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 builder instance, for chaining
- Throws:
IllegalArgumentException-- If you try to mix subcommands/options/groups in one command.
- If the option type is
UNKNOWN. - If the option type is
OptionType.SUB_COMMANDorOptionType.SUB_COMMAND_GROUP. - 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
-
addSubcommands
Add up to 25Subcommandsto this command.- Parameters:
subcommands- The subcommands to add- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException- If null, more than 25 subcommands, or duplicate subcommand names are provided. Also throws if you try to mix subcommands/options/groups in one command.
-
addSubcommands
@Nonnull default SlashCommandData addSubcommands(@Nonnull Collection<? extends SubcommandData> subcommands) Add up to 25Subcommandsto this command.- Parameters:
subcommands- The subcommands to add- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException- If null, more than 25 subcommands, or duplicate subcommand names are provided. Also throws if you try to mix subcommands/options/groups in one command.
-
addSubcommandGroups
Add up to 25Subcommand-Groupsto this command.- Parameters:
groups- The subcommand groups to add- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException- If null, more than 25 subcommand groups, or duplicate group names are provided. Also throws if you try to mix subcommands/options/groups in one command.
-
addSubcommandGroups
@Nonnull default SlashCommandData addSubcommandGroups(@Nonnull Collection<? extends SubcommandGroupData> groups) Add up to 25Subcommand-Groupsto this command.- Parameters:
groups- The subcommand groups to add- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException- If null, more than 25 subcommand groups, or duplicate group names are provided. Also throws if you try to mix subcommands/options/groups in one command.
-
fromCommand
Converts the providedCommandinto a SlashCommandData instance.- Parameters:
command- The command to convert- Returns:
- An instance of SlashCommandData
- Throws:
IllegalArgumentException- If null is provided or the command has illegal configuration- See Also:
-
fromData
Parses the provided serialization back into a SlashCommandData instance.
This is the reverse function forSerializableData.toData().- Parameters:
object- The serializedDataObjectrepresenting the command- Returns:
- The parsed SlashCommandData 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- See Also:
-