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.-
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 options for this command.TheSubcommand Groupsin this command.TheSubcommandsin this command.setDefaultEnabled(boolean enabled) Whether this command is available to everyone by default.setDescription(String description) Configure the descriptionConfigure the command name.Methods inherited from interface net.dv8tion.jda.api.interactions.commands.build.CommandData
getName, getType, isDefaultEnabledMethods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toData
-
Method Details
-
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
-
setDefaultEnabled
Description copied from interface:CommandDataWhether this command is available to everyone by default.
If this is disabled, you need to explicitly whitelist users and roles per guild.You can use
CommandPrivilegeto enable or disable this command per guild for roles and members of the guild. SeeCommand.updatePrivileges(Guild, CommandPrivilege...)andGuild.updateCommandPrivileges(Map).- Specified by:
setDefaultEnabledin interfaceCommandData- Parameters:
enabled- True, if this command is enabled by default for everyone. (Default: true)- 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
-
getDescription
The configured description- Returns:
- The 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.- 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
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
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
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:
-