Interface SlashCommandData
- All Superinterfaces:
CommandData,SerializableData
- All Known Subinterfaces:
CommandCreateAction
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, MAX_OPTIONS -
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.@Unmodifiable List<OptionData>The options for this command.@Unmodifiable List<SubcommandGroupData>TheSubcommand Groupsin this command.@Unmodifiable List<SubcommandData>TheSubcommandsin this command.default booleanremoveOptionByName(String name) Removes options by the provided name.booleanremoveOptions(Predicate<? super OptionData> condition) Removes all options that evaluate totrueunder the providedcondition.default booleanremoveSubcommandByName(String name) Removes subcommands by the provided name.default booleanRemoves subcommand groups by the provided name.booleanremoveSubcommandGroups(Predicate<? super SubcommandGroupData> condition) Removes all subcommand groups that evaluate totrueunder the providedcondition.booleanremoveSubcommands(Predicate<? super SubcommandData> condition) Removes all subcommands that evaluate totrueunder the providedcondition.setContexts(Collection<InteractionContextType> contexts) Sets the contexts in which this command can be used (Default: Guild and Bot DMs).default SlashCommandDatasetContexts(InteractionContextType... contexts) Sets the contexts in which this command can be used (Default: Guild and Bot DMs).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) Deprecated.setIntegrationTypes(Collection<IntegrationType> integrationTypes) Sets the integration types on which this command can be installed on (Default: Guilds).default SlashCommandDatasetIntegrationTypes(IntegrationType... integrationTypes) Sets the integration types on which this command can be installed on (Default: Guilds).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.setNSFW(boolean nsfw) Sets whether this command should only be usable in NSFW (age-restricted) channels.Methods inherited from interface net.dv8tion.jda.api.interactions.commands.build.CommandData
getContexts, getDefaultPermissions, getIntegrationTypes, getName, getNameLocalizations, getType, isGuildOnly, isNSFWMethods 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
Deprecated.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
-
setContexts
Description copied from interface:CommandDataSets the contexts in which this command can be used (Default: Guild and Bot DMs).
This only has an effect if this command is registered globally.- Specified by:
setContextsin interfaceCommandData- Parameters:
contexts- The contexts in which this command can be used- Returns:
- The builder instance, for chaining
-
setContexts
Description copied from interface:CommandDataSets the contexts in which this command can be used (Default: Guild and Bot DMs).
This only has an effect if this command is registered globally.- Specified by:
setContextsin interfaceCommandData- Parameters:
contexts- The contexts in which this command can be used- Returns:
- The builder instance, for chaining
-
setIntegrationTypes
Description copied from interface:CommandDataSets the integration types on which this command can be installed on (Default: Guilds).
This only has an effect if this command is registered globally.- Specified by:
setIntegrationTypesin interfaceCommandData- Parameters:
integrationTypes- The integration types on which this command can be installed on- Returns:
- The builder instance, for chaining
-
setIntegrationTypes
@Nonnull SlashCommandData setIntegrationTypes(@Nonnull Collection<IntegrationType> integrationTypes) Description copied from interface:CommandDataSets the integration types on which this command can be installed on (Default: Guilds).
This only has an effect if this command is registered globally.- Specified by:
setIntegrationTypesin interfaceCommandData- Parameters:
integrationTypes- The integration types on which this command can be installed on- Returns:
- The builder instance, for chaining
-
setNSFW
Description copied from interface:CommandDataSets whether this command should only be usable in NSFW (age-restricted) channels.
Default: falseNote: Age-restricted commands will not show up in direct messages by default unless the user enables them in their settings.
- Specified by:
setNSFWin interfaceCommandData- Parameters:
nsfw- True, to make this command nsfw- Returns:
- The builder instance, for chaining
- See Also:
-
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
-
removeOptions
Removes all options that evaluate totrueunder the providedcondition.
This will not affect options within subcommands. UseSubcommandData.removeOptions(Predicate)instead.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.
This will not affect options within subcommands. UseSubcommandData.removeOptionByName(String)instead.- Parameters:
name- The case-sensitive option name- Returns:
- True, if any options were removed
-
removeSubcommands
Removes all subcommands that evaluate totrueunder the providedcondition.
This will not apply to subcommands within subcommand groups. UseSubcommandGroupData.removeSubcommand(Predicate)instead.Example: Remove all subcommands
command.removeSubcommands(subcommand -> true);- Parameters:
condition- The removal condition (must not throw)- Returns:
- True, if any subcommands were removed
- Throws:
IllegalArgumentException- If the condition is null
-
removeSubcommandByName
Removes subcommands by the provided name.
This will not apply to subcommands within subcommand groups. UseSubcommandGroupData.removeSubcommandByName(String)instead.- Parameters:
name- The case-sensitive subcommand name- Returns:
- True, if any subcommands were removed
-
removeSubcommandGroups
Removes all subcommand groups that evaluate totrueunder the providedcondition.Example: Remove all subcommand groups
command.removeSubcommandGroups(group -> true);- Parameters:
condition- The removal condition (must not throw)- Returns:
- True, if any subcommand groups were removed
- Throws:
IllegalArgumentException- If the condition is null
-
removeSubcommandGroupByName
Removes subcommand groups by the provided name.- Parameters:
name- The case-sensitive subcommand group name- Returns:
- True, if any subcommand groups were removed
-
getSubcommands
TheSubcommandsin this command.- Returns:
- Immutable list of
SubcommandData
-
getSubcommandGroups
TheSubcommand Groupsin this command.- Returns:
- Immutable list of
SubcommandGroupData
-
getOptions
The options for this command.- 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 there already is a subcommand or subcommand group on this command (See
addSubcommands(SubcommandData...)for details). - 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
- If there already is a subcommand or subcommand group on this command (See
-
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 there already is a subcommand or subcommand group on this command (See
addSubcommands(SubcommandData...)for details). - 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
- If there already is a subcommand or subcommand group on this command (See
-
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 there already is a subcommand or subcommand group on this command (See
addSubcommands(SubcommandData...)for details). - 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
- If there already is a subcommand or subcommand group on this command (See
-
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 there already is a subcommand or subcommand group on this command (See
addSubcommands(SubcommandData...)for details). - 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
- If there already is a subcommand or subcommand group on this command (See
-
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 there already is a subcommand or subcommand group on this command (See
addSubcommands(SubcommandData...)for details). - 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
- If there already is a subcommand or subcommand group on this command (See
-
addSubcommands
Add up to 25Subcommandsto this command.
When a subcommand or subcommand group is added, the base command itself cannot be used. Thus usingaddOptions(OptionData...)andaddSubcommands(SubcommandData...)/addSubcommandGroups(SubcommandGroupData...)for the same command, is not supported.Valid command layouts are as follows:
Having an option and subcommand simultaneously is not allowed.command |-- subcommand |__ subcommand group |__ subcommand command |__ subcommand group |__ subcommand command |-- option |__ option- 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 adding subcommands when options are already present.
-
addSubcommands
@Nonnull default SlashCommandData addSubcommands(@Nonnull Collection<? extends SubcommandData> subcommands) Add up to 25Subcommandsto this command.
When a subcommand or subcommand group is added, the base command itself cannot be used. Thus usingaddOptions(OptionData...)andaddSubcommands(SubcommandData...)/addSubcommandGroups(SubcommandGroupData...)for the same command, is not supported.Valid command layouts are as follows:
Having an option and subcommand simultaneously is not allowed.command |-- subcommand |__ subcommand group |__ subcommand command |__ subcommand group |__ subcommand command |-- option |__ option- 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 adding subcommands when options are already present.
-
addSubcommandGroups
Add up to 25Subcommand-Groupsto this command.
When a subcommand or subcommand group is added, the base command itself cannot be used. Thus usingaddOptions(OptionData...)andaddSubcommands(SubcommandData...)/addSubcommandGroups(SubcommandGroupData...)for the same command, is not supported.Valid command layouts are as follows:
Having an option and subcommand simultaneously is not allowed.command |-- subcommand |__ subcommand group |__ subcommand command |__ subcommand group |__ subcommand command |-- option |__ option- 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 adding subcommand groups when options are already present.
-
addSubcommandGroups
@Nonnull default SlashCommandData addSubcommandGroups(@Nonnull Collection<? extends SubcommandGroupData> groups) Add up to 25Subcommand-Groupsto this command.
When a subcommand or subcommand group is added, the base command itself cannot be used. Thus usingaddOptions(OptionData...)andaddSubcommands(SubcommandData...)/addSubcommandGroups(SubcommandGroupData...)for the same command, is not supported.Valid command layouts are as follows:
Having an option and subcommand simultaneously is not allowed.command |-- subcommand |__ subcommand group |__ subcommand command |__ subcommand group |__ subcommand command |-- option |__ option- 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 adding subcommand groups when options are already present.
-
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:
-