Interface CommandData
- All Superinterfaces:
SerializableData
- All Known Subinterfaces:
CommandCreateAction
,SlashCommandData
Builder for Application Commands.
Use the factory methods provided by
Use the factory methods provided by
Commands
to create instances of this interface.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The maximum length the description of a command can be.static final int
The maximum length the name of a command can be.static final int
The maximum amount of options/subcommands/groups that can be added to a command or subcommand. -
Method Summary
Modifier and TypeMethodDescriptionstatic CommandData
fromCommand
(Command command) Converts the providedCommand
into a CommandData instance.static CommandData
fromData
(DataObject object) Parses the provided serialization back into an CommandData instance.Gets theDefaultMemberPermissions
of this command.getName()
The current command nameThe localizations of this command's name forvarious languages
.getType()
TheCommand.Type
boolean
Whether the command can only be used inside a guild.boolean
isNSFW()
Whether this command should only be usable in NSFW (age-restricted) channelssetDefaultPermissions
(DefaultMemberPermissions permission) Sets thePermissions
that a user must have in a specific channel to be able to use this command.setGuildOnly
(boolean guildOnly) Sets whether this command is only usable in a guild (Default: false).setLocalizationFunction
(LocalizationFunction localizationFunction) Sets theLocalizationFunction
for this command
This enables you to have the entirety of this command to be localized.Configure the command name.setNameLocalization
(DiscordLocale locale, String name) Sets alanguage-specific
localization of this command's name.Sets multiplelanguage-specific
localizations of this command's name.setNSFW
(boolean nsfw) Sets whether this command should only be usable in NSFW (age-restricted) channels.Methods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toData
-
Field Details
-
MAX_NAME_LENGTH
static final int MAX_NAME_LENGTHThe maximum length the name of a command can be. (32)- See Also:
-
MAX_DESCRIPTION_LENGTH
static final int MAX_DESCRIPTION_LENGTHThe maximum length the description of a command can be. (100)- See Also:
-
MAX_OPTIONS
static final int MAX_OPTIONSThe maximum amount of options/subcommands/groups that can be added to a command or subcommand. (25)- See Also:
-
-
Method Details
-
setLocalizationFunction
Sets theLocalizationFunction
for this command
This enables you to have the entirety of this command to be localized.- Parameters:
localizationFunction
- The localization function- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException
- If the localization function is null
-
setName
Configure the command name.- Parameters:
name
- The name, 1-32 characters (lowercase and alphanumeric forCommand.Type.SLASH
)- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException
- If the name is not between 1-32 characters long, or not lowercase and alphanumeric for slash commands
-
setNameLocalization
Sets alanguage-specific
localization of this command's name.- Parameters:
locale
- The locale to associate the translated name withname
- The translated name to put- Returns:
- This builder instance, for chaining
- Throws:
IllegalArgumentException
-- If the locale is null
- If the name is null
- If the locale is
DiscordLocale.UNKNOWN
- If the name does not pass the corresponding
name check
-
setNameLocalizations
Sets multiplelanguage-specific
localizations of this command's name.- Parameters:
map
- The map from which to transfer the translated names- Returns:
- This builder instance, for chaining
- Throws:
IllegalArgumentException
-- If the map is null
- If the map contains an
DiscordLocale.UNKNOWN
key - If the map contains a name which does not pass the corresponding
name check
-
setDefaultPermissions
Sets thePermissions
that a user must have in a specific channel to be able to use this command.
By default, everyone can use this command (DefaultMemberPermissions.ENABLED
). Additionally, a command can be disabled for everyone but admins viaDefaultMemberPermissions.DISABLED
.These configurations can be overwritten by moderators in each guild. See
Command.retrievePrivileges(net.dv8tion.jda.api.entities.Guild)
to get moderator defined overrides.- Parameters:
permission
-DefaultMemberPermissions
representing the default permissions of this command.- Returns:
- The builder instance, for chaining
- See Also:
-
setGuildOnly
Sets whether this command is only usable in a guild (Default: false).
This only has an effect if this command is registered globally.- Parameters:
guildOnly
- Whether to restrict this command to guilds- Returns:
- The builder instance, for chaining
-
setNSFW
Sets whether this command should only be usable in NSFW (age-restricted) channels.
Default: falseNote: Age-restricted commands will not show up in direct messages by default unless the user enables them in their settings.
- Parameters:
nsfw
- True, to make this command nsfw- Returns:
- The builder instance, for chaining
- See Also:
-
getName
The current command name- Returns:
- The command name
-
getNameLocalizations
The localizations of this command's name forvarious languages
.- Returns:
- The
LocalizationMap
containing the mapping fromDiscordLocale
to the localized name
-
getType
TheCommand.Type
- Returns:
- The
Command.Type
-
getDefaultPermissions
Gets theDefaultMemberPermissions
of this command.
If no permissions have been set, this returnsDefaultMemberPermissions.ENABLED
.- Returns:
- DefaultMemberPermissions of this command.
- See Also:
-
isGuildOnly
boolean isGuildOnly()Whether the command can only be used inside a guild.
Always true for guild commands.- Returns:
- True, if this command is restricted to guilds.
-
isNSFW
boolean isNSFW()Whether this command should only be usable in NSFW (age-restricted) channels- Returns:
- True, if this command is restricted to NSFW channels
- See Also:
-
fromCommand
Converts the providedCommand
into a CommandData instance.- Parameters:
command
- The command to convert- Returns:
- An instance of CommandData
- Throws:
IllegalArgumentException
- If null is provided or the command has illegal configuration- See Also:
-
fromData
Parses the provided serialization back into an CommandData instance.
This is the reverse function forSerializableData.toData()
.- 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 fieldsIllegalArgumentException
- If any of the values are failing the respective checks such as length- See Also:
-