Class SubcommandData
- java.lang.Object
-
- net.dv8tion.jda.api.interactions.commands.build.SubcommandData
-
- All Implemented Interfaces:
SerializableData
public class SubcommandData extends Object implements SerializableData
Builder for a Slash-Command subcommand.
-
-
Constructor Summary
Constructors Constructor Description SubcommandData(String name, String description)
Create a subcommand builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SubcommandData
addOption(OptionType type, String name, String description)
Adds an option to this subcommand.SubcommandData
addOption(OptionType type, String name, String description, boolean required)
Adds an option to this subcommand.SubcommandData
addOption(OptionType type, String name, String description, boolean required, boolean autoComplete)
Adds an option to this subcommand.SubcommandData
addOptions(Collection<? extends OptionData> options)
Adds up to 25 options to this subcommand.SubcommandData
addOptions(OptionData... options)
Adds up to 25 options to this subcommand.static SubcommandData
fromData(DataObject json)
Parses the provided serialization back into an SubcommandData instance.static SubcommandData
fromSubcommand(Command.Subcommand subcommand)
Converts the providedCommand.Subcommand
into a SubCommandData instance.String
getDescription()
The configured descriptionString
getName()
The configured nameList<OptionData>
getOptions()
The options for this command.SubcommandData
setDescription(String description)
Configure the descriptionSubcommandData
setName(String name)
Configure the nameDataObject
toData()
SerializedDataObject
for this object.
-
-
-
Constructor Detail
-
SubcommandData
public SubcommandData(@Nonnull String name, @Nonnull String description)
Create a subcommand builder.- Parameters:
name
- The subcommand name, 1-32 lowercase alphanumeric charactersdescription
- The subcommand description, 1-100 characters- Throws:
IllegalArgumentException
- If any of the following requirements are not met- The name must be lowercase alphanumeric (with dash), 1-32 characters long
- The description must be 1-100 characters long
-
-
Method Detail
-
setName
@Nonnull public SubcommandData setName(@Nonnull String name)
Configure the name- Parameters:
name
- The lowercase alphanumeric (with dash) name, 1-32 characters- Returns:
- The SubcommandData instance, for chaining
- Throws:
IllegalArgumentException
- If the name is null, not alphanumeric, or not between 1-32 characters
-
setDescription
@Nonnull public SubcommandData setDescription(@Nonnull String description)
Configure the description- Parameters:
description
- The description, 1-100 characters- Returns:
- The SubcommandData instance, for chaining
- Throws:
IllegalArgumentException
- If the name is null or not between 1-100 characters
-
addOptions
@Nonnull public SubcommandData addOptions(@Nonnull OptionData... options)
Adds up to 25 options to this subcommand.Required options must be added before non-required options!
- Parameters:
options
- Theoptions
to add- Returns:
- The SubcommandData instance, for chaining
- Throws:
IllegalArgumentException
-- 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 public SubcommandData addOptions(@Nonnull Collection<? extends OptionData> options)
Adds up to 25 options to this subcommand.Required options must be added before non-required options!
- Parameters:
options
- Theoptions
to add- Returns:
- The SubcommandData instance, for chaining
- Throws:
IllegalArgumentException
-- 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 public SubcommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean required, boolean autoComplete)
Adds an option to this subcommand.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 SubcommandData instance, for chaining
- Throws:
IllegalArgumentException
-- If this option is required and you already added a non-required option.
- If the provided option type does not support auto-complete
- If more than 25 options are provided.
- If the option name is not unique
- If null is provided
-
addOption
@Nonnull public SubcommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean required)
Adds an option to this subcommand.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 SubcommandData instance, for chaining
- Throws:
IllegalArgumentException
-- 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 public SubcommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description)
Adds an option to this subcommand.
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 SubcommandData instance, for chaining
- Throws:
IllegalArgumentException
-- 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
-
getOptions
@Nonnull public List<OptionData> getOptions()
The options for this command.- Returns:
- Immutable list of
OptionData
-
getDescription
@Nonnull public String getDescription()
The configured description- Returns:
- The description
-
toData
@Nonnull public DataObject toData()
Description copied from interface:SerializableData
SerializedDataObject
for this object.- Specified by:
toData
in interfaceSerializableData
- Returns:
DataObject
-
fromData
@Nonnull public static SubcommandData fromData(@Nonnull DataObject json)
Parses the provided serialization back into an SubcommandData instance.
This is the reverse function fortoData()
.- Parameters:
json
- The serializedDataObject
representing the subcommand- Returns:
- The parsed SubcommandData 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
-
fromSubcommand
@Nonnull public static SubcommandData fromSubcommand(@Nonnull Command.Subcommand subcommand)
Converts the providedCommand.Subcommand
into a SubCommandData instance.- Parameters:
subcommand
- The subcommand to convert- Returns:
- An instance of SubCommandData
- Throws:
IllegalArgumentException
- If null is provided or the subcommand has illegal configuration
-
-