Interface SlashCommandData
-
- All Superinterfaces:
CommandData
,SerializableData
- All Known Subinterfaces:
CommandCreateAction
public interface SlashCommandData extends CommandData
Extension ofCommandData
which allows setting slash-command specific settings such as options and subcommands.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default 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.SlashCommandData
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.SlashCommandData
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.SlashCommandData
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.String
getDescription()
The configured descriptionList<OptionData>
getOptions()
The options for this command.List<SubcommandGroupData>
getSubcommandGroups()
TheSubcommand Groups
in this command.List<SubcommandData>
getSubcommands()
TheSubcommands
in this command.SlashCommandData
setDefaultEnabled(boolean enabled)
Whether this command is available to everyone by default.SlashCommandData
setDescription(String description)
Configure the descriptionSlashCommandData
setName(String name)
Configure the command name.-
Methods inherited from interface net.dv8tion.jda.api.interactions.commands.build.CommandData
getName, getType, isDefaultEnabled
-
Methods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toData
-
-
-
-
Method Detail
-
setName
@Nonnull SlashCommandData setName(@Nonnull String name)
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
-
setDefaultEnabled
@Nonnull SlashCommandData setDefaultEnabled(boolean enabled)
Description copied from interface:CommandData
Whether 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
CommandPrivilege
to enable or disable this command per guild for roles and members of the guild. SeeCommand.updatePrivileges(Guild, CommandPrivilege...)
andGuild.updateCommandPrivileges(Map)
.- Specified by:
setDefaultEnabled
in interfaceCommandData
- Parameters:
enabled
- True, if this command is enabled by default for everyone. (Default: true)- Returns:
- The builder instance, for chaining
-
setDescription
@Nonnull SlashCommandData setDescription(@Nonnull String description)
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
-
getSubcommands
@Nonnull List<SubcommandData> getSubcommands()
TheSubcommands
in 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
@Nonnull List<SubcommandGroupData> getSubcommandGroups()
TheSubcommand Groups
in 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
@Nonnull List<OptionData> getOptions()
The options for this command.- Returns:
- Immutable list of
OptionData
-
addOptions
@Nonnull SlashCommandData addOptions(@Nonnull OptionData... options)
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 you try to mix subcommands/options/groups in one command.
- 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
-
addOptions
@Nonnull default SlashCommandData addOptions(@Nonnull Collection<? extends OptionData> options)
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 you try to mix subcommands/options/groups in one command.
- 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
-
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 you try to mix subcommands/options/groups in one command.
- 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
-
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 you try to mix subcommands/options/groups in one command.
- 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
-
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 you try to mix subcommands/options/groups in one command.
- 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
-
addSubcommands
@Nonnull SlashCommandData addSubcommands(@Nonnull SubcommandData... subcommands)
Add up to 25Subcommands
to 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 25Subcommands
to 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
@Nonnull SlashCommandData addSubcommandGroups(@Nonnull SubcommandGroupData... groups)
Add up to 25Subcommand-Groups
to 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-Groups
to 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
@Nonnull static SlashCommandData fromCommand(@Nonnull Command command)
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:
fromCommand(Command)
-
fromData
@Nonnull static SlashCommandData fromData(@Nonnull DataObject object)
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:
CommandData.fromData(DataObject)
,Commands.fromList(Collection)
-
-