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 SlashCommandData
addOption
(OptionType type, String name, String description) Adds an option to this command.default SlashCommandData
addOption
(OptionType type, String name, String description, boolean required) Adds an option to this command.default SlashCommandData
addOption
(OptionType type, String name, String description, boolean required, boolean autoComplete) Adds an option to this command.default SlashCommandData
addOptions
(Collection<? extends OptionData> options) Adds up to 25 options to this command.addOptions
(OptionData... options) Adds up to 25 options to this command.default SlashCommandData
addSubcommandGroups
(Collection<? extends SubcommandGroupData> groups) Add up to 25Subcommand-Groups
to this command.addSubcommandGroups
(SubcommandGroupData... groups) Add up to 25Subcommand-Groups
to this command.default SlashCommandData
addSubcommands
(Collection<? extends SubcommandData> subcommands) Add up to 25Subcommands
to this command.addSubcommands
(SubcommandData... subcommands) Add up to 25Subcommands
to this command.static SlashCommandData
fromCommand
(Command command) Converts the providedCommand
into a SlashCommandData instance.static SlashCommandData
fromData
(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 Groups
in this command.@Unmodifiable List<SubcommandData>
TheSubcommands
in this command.default boolean
removeOptionByName
(String name) Removes options by the provided name.boolean
removeOptions
(Predicate<? super OptionData> condition) Removes all options that evaluate totrue
under the providedcondition
.default boolean
removeSubcommandByName
(String name) Removes subcommands by the provided name.default boolean
Removes subcommand groups by the provided name.boolean
removeSubcommandGroups
(Predicate<? super SubcommandGroupData> condition) Removes all subcommand groups that evaluate totrue
under the providedcondition
.boolean
removeSubcommands
(Predicate<? super SubcommandData> condition) Removes all subcommands that evaluate totrue
under the providedcondition
.setDefaultPermissions
(DefaultMemberPermissions permission) Sets thePermissions
that 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-specific
localizations of this command's description.Sets multiplelanguage-specific
localizations of this command's description.setGuildOnly
(boolean guildOnly) Sets whether this command is only usable in a guild (Default: false).setLocalizationFunction
(LocalizationFunction localizationFunction) Sets theLocalizationFunction
for 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-specific
localization of this command's name.Sets multiplelanguage-specific
localizations 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
getDefaultPermissions, getName, getNameLocalizations, getType, isGuildOnly, isNSFW
Methods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toData
-
Method Details
-
setLocalizationFunction
@Nonnull SlashCommandData setLocalizationFunction(@Nonnull LocalizationFunction localizationFunction) Description copied from interface:CommandData
Sets theLocalizationFunction
for this command
This enables you to have the entirety of this command to be localized.- Specified by:
setLocalizationFunction
in interfaceCommandData
- Parameters:
localizationFunction
- The localization function- Returns:
- The builder instance, for chaining
-
setName
Description copied from interface:CommandData
Configure the command name.- Specified by:
setName
in 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:CommandData
Sets alanguage-specific
localization of this command's name.- Specified by:
setNameLocalization
in 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:CommandData
Sets multiplelanguage-specific
localizations of this command's name.- Specified by:
setNameLocalizations
in interfaceCommandData
- Parameters:
map
- The map from which to transfer the translated names- Returns:
- This builder instance, for chaining
-
setDefaultPermissions
Description copied from interface:CommandData
Sets thePermissions
that 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:
setDefaultPermissions
in interfaceCommandData
- Parameters:
permission
-DefaultMemberPermissions
representing the default permissions of this command.- Returns:
- The builder instance, for chaining
- See Also:
-
setGuildOnly
Description copied from interface:CommandData
Sets whether this command is only usable in a guild (Default: false).
This only has an effect if this command is registered globally.- Specified by:
setGuildOnly
in interfaceCommandData
- Parameters:
guildOnly
- Whether to restrict this command to guilds- Returns:
- The builder instance, for chaining
-
setNSFW
Description copied from interface:CommandData
Sets 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:
setNSFW
in 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-specific
localizations 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-specific
localizations 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.UNKNOWN
key - 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
LocalizationMap
containing the mapping fromDiscordLocale
to the localized description
-
removeOptions
Removes all options that evaluate totrue
under 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 totrue
under 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 totrue
under 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
TheSubcommands
in this command.- Returns:
- Immutable list of
SubcommandData
-
getSubcommandGroups
TheSubcommand Groups
in 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
- TheOptions
to 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_COMMAND
orOptionType.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
- TheOptions
to 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_COMMAND
orOptionType.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
- TheOptionType
name
- 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_COMMAND
orOptionType.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
- TheOptionType
name
- 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_COMMAND
orOptionType.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
- TheOptionType
name
- 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_COMMAND
orOptionType.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 25Subcommands
to 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 25Subcommands
to 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-Groups
to 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-Groups
to 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 providedCommand
into 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 serializedDataObject
representing 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:
-