Class Commands
- java.lang.Object
-
- net.dv8tion.jda.api.interactions.commands.build.Commands
-
public class Commands extends Object
Provides various static factory methods for building commands of different types. This also includes context menu items.
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_MESSAGE_COMMANDS
Maximum amount of global or guild message context commandsstatic int
MAX_SLASH_COMMANDS
Maximum amount of global or guild slash commandsstatic int
MAX_USER_COMMANDS
Maximum amount of global or guild user context commands
-
Constructor Summary
Constructors Constructor Description Commands()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CommandData
context(Command.Type type, String name)
Create a context menu command builder for the specified command type.static List<CommandData>
fromList(Collection<? extends DataObject> collection)
Parses the provided serialization back into an CommandData instance.static List<CommandData>
fromList(DataArray array)
Parses the provided serialization back into an CommandData instance.static CommandData
message(String name)
Create a message context menu command builder.static SlashCommandData
slash(String name, String description)
Create a slash command builder.static CommandData
user(String name)
Create a user context menu command builder.
-
-
-
Field Detail
-
MAX_SLASH_COMMANDS
public static final int MAX_SLASH_COMMANDS
Maximum amount of global or guild slash commands- See Also:
- Constant Field Values
-
MAX_USER_COMMANDS
public static final int MAX_USER_COMMANDS
Maximum amount of global or guild user context commands- See Also:
- Constant Field Values
-
MAX_MESSAGE_COMMANDS
public static final int MAX_MESSAGE_COMMANDS
Maximum amount of global or guild message context commands- See Also:
- Constant Field Values
-
-
Method Detail
-
slash
@Nonnull public static SlashCommandData slash(@Nonnull String name, @Nonnull String description)
Create a slash command builder.- Parameters:
name
- The command name, 1-32 lowercase alphanumeric charactersdescription
- The command description, 1-100 characters- Returns:
SlashCommandData
builder for slash commands- 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
-
message
@Nonnull public static CommandData message(@Nonnull String name)
Create a message context menu command builder.- Parameters:
name
- The command name, 1-32 characters- Returns:
CommandData
- Throws:
IllegalArgumentException
- If the name is not between 1-32 characters long
-
user
@Nonnull public static CommandData user(@Nonnull String name)
Create a user context menu command builder.- Parameters:
name
- The command name, 1-32 characters- Returns:
CommandData
- Throws:
IllegalArgumentException
- If the name is not between 1-32 characters long
-
context
@Nonnull public static CommandData context(@Nonnull Command.Type type, @Nonnull String name)
Create a context menu command builder for the specified command type.
This cannot be used for slash commands, because they require a description. Useslash(String, String)
to create a slash command.- Parameters:
type
- The command type, must not beSLASH
name
- The command name, 1-32 characters- Returns:
CommandData
- Throws:
IllegalArgumentException
- If the name is not between 1-32 characters long, the type isCommand.Type.SLASH
, or the type is null.
-
fromList
@Nonnull public static List<CommandData> fromList(@Nonnull DataArray array)
Parses the provided serialization back into an CommandData instance.
This is the reverse function forSerializableData.toData()
.- 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 fieldsIllegalArgumentException
- If any of the values are failing the respective checks such as length- See Also:
CommandData.fromData(DataObject)
,SlashCommandData.fromData(DataObject)
-
fromList
@Nonnull public static List<CommandData> fromList(@Nonnull Collection<? extends DataObject> collection)
Parses the provided serialization back into an CommandData instance.
This is the reverse function forSerializableData.toData()
.- 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 fieldsIllegalArgumentException
- If any of the values are failing the respective checks such as length- See Also:
CommandData.fromData(DataObject)
,SlashCommandData.fromData(DataObject)
-
-