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
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum length the description of a command can be.static final intThe maximum length the name of a command can be.static final intThe maximum amount of options/subcommands/groups that can be added to a command or subcommand. -
Method Summary
Modifier and TypeMethodDescriptionstatic CommandDatafromCommand(Command command) Converts the providedCommandinto a CommandData instance.static CommandDatafromData(DataObject object) Parses the provided serialization back into an CommandData instance.@UnmodifiableView Set<InteractionContextType>The contexts in which this command can be used.Gets theDefaultMemberPermissionsof this command.@UnmodifiableView Set<IntegrationType>Gets the integration types on which this command can be installed on.getName()The current command nameThe localizations of this command's name forvarious languages.getType()TheCommand.TypebooleanDeprecated.booleanisNSFW()Whether this command should only be usable in NSFW (age-restricted) channelssetContexts(Collection<InteractionContextType> contexts) Sets the contexts in which this command can be used (Default: Guild and Bot DMs).default CommandDatasetContexts(InteractionContextType... contexts) Sets the contexts in which this command can be used (Default: Guild and Bot DMs).setDefaultPermissions(DefaultMemberPermissions permission) Sets thePermissionsthat a user must have in a specific channel to be able to use this command.setGuildOnly(boolean guildOnly) Deprecated.Replaced withsetContexts(InteractionContextType...)setIntegrationTypes(Collection<IntegrationType> integrationTypes) Sets the integration types on which this command can be installed on (Default: Guilds).default CommandDatasetIntegrationTypes(IntegrationType... integrationTypes) Sets the integration types on which this command can be installed on (Default: Guilds).setLocalizationFunction(LocalizationFunction localizationFunction) Sets theLocalizationFunctionfor 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-specificlocalization of this command's name.Sets multiplelanguage-specificlocalizations 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 theLocalizationFunctionfor 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-specificlocalization 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-specificlocalizations 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.UNKNOWNkey - If the map contains a name which does not pass the corresponding
name check
-
setDefaultPermissions
Sets thePermissionsthat 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-DefaultMemberPermissionsrepresenting the default permissions of this command.- Returns:
- The builder instance, for chaining
- See Also:
-
setGuildOnly
@Nonnull @Deprecated @ReplaceWith("setContexts(InteractionContextType.GUILD)") CommandData setGuildOnly(boolean guildOnly) Deprecated.Replaced withsetContexts(InteractionContextType...)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
-
setContexts
Sets the contexts in which this command can be used (Default: Guild and Bot DMs).
This only has an effect if this command is registered globally.- Parameters:
contexts- The contexts in which this command can be used- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException- Ifnullor no interaction context types were passed
-
setContexts
Sets the contexts in which this command can be used (Default: Guild and Bot DMs).
This only has an effect if this command is registered globally.- Parameters:
contexts- The contexts in which this command can be used- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException- Ifnullor no interaction context types were passed
-
setIntegrationTypes
Sets the integration types on which this command can be installed on (Default: Guilds).
This only has an effect if this command is registered globally.- Parameters:
integrationTypes- The integration types on which this command can be installed on- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException- Ifnullor no integration types were passed
-
setIntegrationTypes
Sets the integration types on which this command can be installed on (Default: Guilds).
This only has an effect if this command is registered globally.- Parameters:
integrationTypes- The integration types on which this command can be installed on- Returns:
- The builder instance, for chaining
- Throws:
IllegalArgumentException- Ifnullor no integration types were passed
-
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
LocalizationMapcontaining the mapping fromDiscordLocaleto the localized name
-
getType
TheCommand.Type- Returns:
- The
Command.Type
-
getDefaultPermissions
Gets theDefaultMemberPermissionsof this command.
If no permissions have been set, this returnsDefaultMemberPermissions.ENABLED.- Returns:
- DefaultMemberPermissions of this command.
- See Also:
-
isGuildOnly
@Deprecated @ReplaceWith("getContexts().equals(EnumSet.of(InteractionContextType.GUILD))") boolean isGuildOnly()Deprecated.Replaced withgetContexts()Whether the command can only be used inside a guild.
Always true for guild commands.- Returns:
- True, if this command is restricted to guilds.
-
getContexts
The contexts in which this command can be used.- Returns:
- The contexts in which this command can be used
-
getIntegrationTypes
Gets the integration types on which this command can be installed on.- Returns:
- The integration types on which this command can be installed on
-
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 providedCommandinto 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 serializedDataObjectrepresenting 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:
-
getContexts()