Class CommandData
- java.lang.Object
-
- net.dv8tion.jda.api.interactions.commands.build.BaseCommand<CommandData>
-
- net.dv8tion.jda.api.interactions.commands.build.CommandData
-
- All Implemented Interfaces:
SerializableData
public class CommandData extends BaseCommand<CommandData> implements SerializableData
Builder for a Slash-Command.
-
-
Constructor Summary
Constructors Constructor Description CommandData(java.lang.String name, java.lang.String description)
Create an command builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CommandData
addOption(OptionType type, java.lang.String name, java.lang.String description)
Adds an option to this command.CommandData
addOption(OptionType type, java.lang.String name, java.lang.String description, boolean required)
Adds an option to this command.CommandData
addOptions(java.util.Collection<? extends OptionData> options)
Adds up to 25 options to this command.CommandData
addOptions(OptionData... options)
Adds up to 25 options to this command.CommandData
addSubcommandGroups(java.util.Collection<? extends SubcommandGroupData> groups)
Add up to 25Subcommand-Groups
to this command.CommandData
addSubcommandGroups(SubcommandGroupData... groups)
Add up to 25Subcommand-Groups
to this command.CommandData
addSubcommands(java.util.Collection<? extends SubcommandData> subcommands)
Add up to 25Subcommands
to this command.CommandData
addSubcommands(SubcommandData... subcommands)
Add up to 25Subcommands
to this command.static CommandData
fromData(DataObject object)
Parses the provided serialization back into an CommandData instance.static java.util.List<CommandData>
fromList(java.util.Collection<? extends DataObject> collection)
Parses the provided serialization back into an CommandData instance.static java.util.List<CommandData>
fromList(DataArray array)
Parses the provided serialization back into an CommandData instance.java.util.List<SubcommandGroupData>
getSubcommandGroups()
TheSubcommand Groups
in this command.java.util.List<SubcommandData>
getSubcommands()
TheSubcommands
in this command.CommandData
setDefaultEnabled(boolean enabled)
Whether this command is available to everyone by default.DataObject
toData()
SerializedDataObject
for this object.-
Methods inherited from class net.dv8tion.jda.api.interactions.commands.build.BaseCommand
getDescription, getName, getOptions, setDescription, setName
-
-
-
-
Constructor Detail
-
CommandData
public CommandData(@Nonnull java.lang.String name, @Nonnull java.lang.String description)
Create an command builder.- Parameters:
name
- The command name, 1-32 lowercase alphanumeric charactersdescription
- The command description, 1-100 characters- Throws:
java.lang.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
-
toData
@Nonnull public DataObject toData()
Description copied from interface:SerializableData
SerializedDataObject
for this object.- Specified by:
toData
in interfaceSerializableData
- Overrides:
toData
in classBaseCommand<CommandData>
- Returns:
DataObject
-
getSubcommands
@Nonnull public java.util.List<SubcommandData> getSubcommands()
TheSubcommands
in this command.- Returns:
- Immutable list of
SubcommandData
-
getSubcommandGroups
@Nonnull public java.util.List<SubcommandGroupData> getSubcommandGroups()
TheSubcommand Groups
in this command.- Returns:
- Immutable list of
SubcommandGroupData
-
setDefaultEnabled
@Nonnull public CommandData setDefaultEnabled(boolean enabled)
Whether this command is available to everyone by default.
If this is disabled, you need to explicitly whitelist users and roles per guild.- Parameters:
enabled
- True, if this command is enabled by default for everyone. (Default: true)- Returns:
- The CommandData instance, for chaining
-
addOptions
@Nonnull public CommandData 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 CommandData instance, for chaining
- Throws:
java.lang.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 null is provided
-
addOptions
@Nonnull public CommandData addOptions(@Nonnull java.util.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 CommandData instance, for chaining
- Throws:
java.lang.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 null is provided
-
addOption
@Nonnull public CommandData addOption(@Nonnull OptionType type, @Nonnull java.lang.String name, @Nonnull java.lang.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 CommandData instance, for chaining
- Throws:
java.lang.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 null is provided
-
addOption
@Nonnull public CommandData addOption(@Nonnull OptionType type, @Nonnull java.lang.String name, @Nonnull java.lang.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 CommandData instance, for chaining
- Throws:
java.lang.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 null is provided
-
addSubcommands
@Nonnull public CommandData addSubcommands(@Nonnull SubcommandData... subcommands)
Add up to 25Subcommands
to this command.- Parameters:
subcommands
- The subcommands to add- Returns:
- The CommandData instance, for chaining
- Throws:
java.lang.IllegalArgumentException
- If null is provided, or more than 25 subcommands are provided. Also throws if you try to mix subcommands/options/groups in one command.
-
addSubcommands
@Nonnull public CommandData addSubcommands(@Nonnull java.util.Collection<? extends SubcommandData> subcommands)
Add up to 25Subcommands
to this command.- Parameters:
subcommands
- The subcommands to add- Returns:
- The CommandData instance, for chaining
- Throws:
java.lang.IllegalArgumentException
- If null is provided, or more than 25 subcommands are provided. Also throws if you try to mix subcommands/options/groups in one command.
-
addSubcommandGroups
@Nonnull public CommandData addSubcommandGroups(@Nonnull SubcommandGroupData... groups)
Add up to 25Subcommand-Groups
to this command.- Parameters:
groups
- The subcommand groups to add- Returns:
- The CommandData instance, for chaining
- Throws:
java.lang.IllegalArgumentException
- If null is provided, or more than 25 subcommand groups are provided. Also throws if you try to mix subcommands/options/groups in one command.
-
addSubcommandGroups
@Nonnull public CommandData addSubcommandGroups(@Nonnull java.util.Collection<? extends SubcommandGroupData> groups)
Add up to 25Subcommand-Groups
to this command.- Parameters:
groups
- The subcommand groups to add- Returns:
- The CommandData instance, for chaining
- Throws:
java.lang.IllegalArgumentException
- If null is provided, or more than 25 subcommand groups are provided. Also throws if you try to mix subcommands/options/groups in one command.
-
fromData
@Nonnull public static CommandData fromData(@Nonnull DataObject object)
Parses the provided serialization back into an CommandData instance.
This is the reverse function fortoData()
.- Parameters:
object
- The serializedDataObject
representing the command- Returns:
- The parsed CommandData instance, which can be further configured through setters
- Throws:
ParsingException
- If the serialized object is missing required fieldsjava.lang.IllegalArgumentException
- If any of the values are failing the respective checks such as length
-
fromList
@Nonnull public static java.util.List<CommandData> fromList(@Nonnull DataArray array)
Parses the provided serialization back into an CommandData instance.
This is the reverse function fortoData()
.- Parameters:
array
- Array of serializedDataObject
representing the commands- Returns:
- The parsed CommandData instances, which can be further configured through setters
- Throws:
ParsingException
- If the serialized object is missing required fieldsjava.lang.IllegalArgumentException
- If any of the values are failing the respective checks such as length
-
fromList
@Nonnull public static java.util.List<CommandData> fromList(@Nonnull java.util.Collection<? extends DataObject> collection)
Parses the provided serialization back into an CommandData instance.
This is the reverse function fortoData()
.- Parameters:
collection
- Collection of serializedDataObject
representing the commands- Returns:
- The parsed CommandData instances, which can be further configured through setters
- Throws:
ParsingException
- If the serialized object is missing required fieldsjava.lang.IllegalArgumentException
- If any of the values are failing the respective checks such as length
-
-