Interface CommandCreateAction
- All Superinterfaces:
CommandData
,RestAction<Command>
,SerializableData
,SlashCommandData
RestAction
used to create or update commands.
If a command with the specified name already exists, it will be replaced!
This operation is not idempotent! Commands will persist between restarts of your bot, you only have to create a command once.
-
Field Summary
Fields inherited from interface net.dv8tion.jda.api.interactions.commands.build.CommandData
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH, MAX_OPTIONS
-
Method Summary
Modifier and TypeMethodDescriptionaddCheck
(BooleanSupplier checks) Shortcut forsetCheck(() -> getCheck().getAsBoolean() && checks.getAsBoolean())
.default CommandCreateAction
addOption
(OptionType type, String name, String description) Adds an option to this command.default CommandCreateAction
addOption
(OptionType type, String name, String description, boolean required) Adds an option to this command.default CommandCreateAction
addOption
(OptionType type, String name, String description, boolean required, boolean autoComplete) Adds an option to this command.default CommandCreateAction
addOptions
(Collection<? extends OptionData> options) Adds up to 25 options to this command.addOptions
(OptionData... options) Adds up to 25 options to this command.default CommandCreateAction
addSubcommandGroups
(Collection<? extends SubcommandGroupData> groups) Add up to 25Subcommand-Groups
to this command.addSubcommandGroups
(SubcommandGroupData... groups) Add up to 25Subcommand-Groups
to this command.default CommandCreateAction
addSubcommands
(Collection<? extends SubcommandData> subcommands) Add up to 25Subcommands
to this command.addSubcommands
(SubcommandData... subcommands) Add up to 25Subcommands
to this command.deadline
(long timestamp) Similar toRestAction.timeout(long, TimeUnit)
but schedules a deadline at which the request has to be completed.setCheck
(BooleanSupplier checks) Sets the last-second checks before finally executing the http request in the queue.setDefaultPermissions
(DefaultMemberPermissions permission) Sets thePermissions
that a user must have in a specific channel to be able to use this command.setDescription
(String description) Configure the descriptionsetDescriptionLocalization
(DiscordLocale locale, String description) Sets alanguage-specific
localizations of this command's description.Sets multiplelanguage-specific
localizations of this command's description.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.Timeout for this RestAction instance.Methods inherited from interface net.dv8tion.jda.api.interactions.commands.build.CommandData
getDefaultPermissions, getName, getNameLocalizations, getType, isGuildOnly, isNSFW
Methods inherited from interface net.dv8tion.jda.api.requests.RestAction
and, and, complete, complete, completeAfter, delay, delay, delay, delay, flatMap, flatMap, getCheck, getJDA, map, mapToResult, onErrorFlatMap, onErrorFlatMap, onErrorMap, onErrorMap, onSuccess, queue, queue, queue, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, submit, submit, submitAfter, submitAfter, zip
Methods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toData
Methods inherited from interface net.dv8tion.jda.api.interactions.commands.build.SlashCommandData
getDescription, getDescriptionLocalizations, getOptions, getSubcommandGroups, getSubcommands, removeOptionByName, removeOptions, removeSubcommandByName, removeSubcommandGroupByName, removeSubcommandGroups, removeSubcommands
-
Method Details
-
setCheck
Description copied from interface:RestAction
Sets the last-second checks before finally executing the http request in the queue.
If the provided supplier evaluates tofalse
or throws an exception this will not be finished. When an exception is thrown from the supplier it will be provided to the failure callback.- Specified by:
setCheck
in interfaceRestAction<Command>
- Parameters:
checks
- The checks to run before executing the request, ornull
to run no checks- Returns:
- The current RestAction for chaining convenience
- See Also:
-
addCheck
Description copied from interface:RestAction
Shortcut forsetCheck(() -> getCheck().getAsBoolean() && checks.getAsBoolean())
.- Specified by:
addCheck
in interfaceRestAction<Command>
- Parameters:
checks
- Other checks to run- Returns:
- The current RestAction for chaining convenience
- See Also:
-
timeout
Description copied from interface:RestAction
Timeout for this RestAction instance.
If the request doesn't get executed within the timeout it will fail.When a RestAction times out, it will fail with a
TimeoutException
. This is the same asdeadline(System.currentTimeMillis() + unit.toMillis(timeout))
.Example
action.timeout(10, TimeUnit.SECONDS) // 10 seconds from now .queueAfter(20, SECONDS); // request will not be executed within deadline and timeout immediately after 20 seconds
- Specified by:
timeout
in interfaceRestAction<Command>
- Parameters:
timeout
- The timeout to useunit
-Unit
for the timeout value- Returns:
- The same RestAction instance with the applied timeout
- See Also:
-
deadline
Description copied from interface:RestAction
Similar toRestAction.timeout(long, TimeUnit)
but schedules a deadline at which the request has to be completed.
If the deadline is reached, the request will fail with aTimeoutException
.This does not mean that the request will immediately timeout when the deadline is reached. JDA will check the deadline right before executing the request or within intervals in a worker thread. This only means the request will timeout if the deadline has passed.
Example
action.deadline(System.currentTimeMillis() + 10000) // 10 seconds from now .queueAfter(20, SECONDS); // request will not be executed within deadline and timeout immediately after 20 seconds
- Specified by:
deadline
in interfaceRestAction<Command>
- Parameters:
timestamp
- Millisecond timestamp at which the request will timeout- Returns:
- The same RestAction with the applied deadline
- See Also:
-
setLocalizationFunction
@Nonnull @CheckReturnValue CommandCreateAction setLocalizationFunction(@Nonnull LocalizationFunction localizationFunction) Description copied from interface:CommandData
Sets theLocalizationFunction
for this command
This enables you to have the entirety of this command to be localized.- Specified by:
setLocalizationFunction
in interfaceCommandData
- Specified by:
setLocalizationFunction
in interfaceSlashCommandData
- Parameters:
localizationFunction
- The localization function- Returns:
- The builder instance, for chaining
-
setName
Description copied from interface:CommandData
Configure the command name.- Specified by:
setName
in interfaceCommandData
- Specified by:
setName
in interfaceSlashCommandData
- Parameters:
name
- The name, 1-32 characters (lowercase and alphanumeric forCommand.Type.SLASH
)- Returns:
- The builder instance, for chaining
-
setNameLocalization
@Nonnull @CheckReturnValue CommandCreateAction setNameLocalization(@Nonnull DiscordLocale locale, @Nonnull String name) Description copied from interface:CommandData
Sets alanguage-specific
localization of this command's name.- Specified by:
setNameLocalization
in interfaceCommandData
- Specified by:
setNameLocalization
in interfaceSlashCommandData
- Parameters:
locale
- The locale to associate the translated name withname
- The translated name to put- Returns:
- This builder instance, for chaining
-
setNameLocalizations
@Nonnull @CheckReturnValue CommandCreateAction setNameLocalizations(@Nonnull Map<DiscordLocale, String> map) Description copied from interface:CommandData
Sets multiplelanguage-specific
localizations of this command's name.- Specified by:
setNameLocalizations
in interfaceCommandData
- Specified by:
setNameLocalizations
in interfaceSlashCommandData
- Parameters:
map
- The map from which to transfer the translated names- Returns:
- This builder instance, for chaining
-
setDescription
Description copied from interface:SlashCommandData
Configure the description- Specified by:
setDescription
in interfaceSlashCommandData
- Parameters:
description
- The description, 1-100 characters- Returns:
- The builder, for chaining
-
setDescriptionLocalization
@Nonnull @CheckReturnValue CommandCreateAction setDescriptionLocalization(@Nonnull DiscordLocale locale, @Nonnull String description) Description copied from interface:SlashCommandData
Sets alanguage-specific
localizations of this command's description.- Specified by:
setDescriptionLocalization
in interfaceSlashCommandData
- Parameters:
locale
- The locale to associate the translated description withdescription
- The translated description to put- Returns:
- This builder instance, for chaining
-
setDescriptionLocalizations
@Nonnull @CheckReturnValue CommandCreateAction setDescriptionLocalizations(@Nonnull Map<DiscordLocale, String> map) Description copied from interface:SlashCommandData
Sets multiplelanguage-specific
localizations of this command's description.- Specified by:
setDescriptionLocalizations
in interfaceSlashCommandData
- Parameters:
map
- The map from which to transfer the translated descriptions- Returns:
- This builder instance, for chaining
-
addOptions
Description copied from interface:SlashCommandData
Adds up to 25 options to this command.Required options must be added before non-required options!
- Specified by:
addOptions
in interfaceSlashCommandData
- Parameters:
options
- TheOptions
to add- Returns:
- The builder instance, for chaining
-
addOptions
@Nonnull @CheckReturnValue default CommandCreateAction addOptions(@Nonnull Collection<? extends OptionData> options) Description copied from interface:SlashCommandData
Adds up to 25 options to this command.Required options must be added before non-required options!
- Specified by:
addOptions
in interfaceSlashCommandData
- Parameters:
options
- TheOptions
to add- Returns:
- The builder instance, for chaining
-
addOption
@Nonnull @CheckReturnValue default CommandCreateAction addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean required, boolean autoComplete) Description copied from interface:SlashCommandData
Adds an option to this command.Required options must be added before non-required options!
- Specified by:
addOption
in interfaceSlashCommandData
- 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 builder instance, for chaining
-
addOption
@Nonnull @CheckReturnValue default CommandCreateAction addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean required) Description copied from interface:SlashCommandData
Adds an option to this command.Required options must be added before non-required options!
- Specified by:
addOption
in interfaceSlashCommandData
- 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 builder instance, for chaining
-
addOption
@Nonnull @CheckReturnValue default CommandCreateAction addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description) Description copied from interface:SlashCommandData
Adds an option to this command.
The option is set to be non-required! You can useSlashCommandData.addOption(OptionType, String, String, boolean)
to add a required option instead.Required options must be added before non-required options!
- Specified by:
addOption
in interfaceSlashCommandData
- Parameters:
type
- TheOptionType
name
- The lowercase option name, 1-32 charactersdescription
- The option description, 1-100 characters- Returns:
- The builder instance, for chaining
-
addSubcommands
@Nonnull @CheckReturnValue CommandCreateAction addSubcommands(@Nonnull SubcommandData... subcommands) Description copied from interface:SlashCommandData
Add up to 25Subcommands
to this command.
When a subcommand or subcommand group is added, the base command itself cannot be used. Thus usingSlashCommandData.addOptions(OptionData...)
andSlashCommandData.addSubcommands(SubcommandData...)
/SlashCommandData.addSubcommandGroups(SubcommandGroupData...)
for the same command, is not supported.Valid command layouts are as follows:
Having an option and subcommand simultaneously is not allowed.command |-- subcommand |__ subcommand group |__ subcommand command |__ subcommand group |__ subcommand command |-- option |__ option
- Specified by:
addSubcommands
in interfaceSlashCommandData
- Parameters:
subcommands
- The subcommands to add- Returns:
- The builder instance, for chaining
-
addSubcommands
@Nonnull @CheckReturnValue default CommandCreateAction addSubcommands(@Nonnull Collection<? extends SubcommandData> subcommands) Description copied from interface:SlashCommandData
Add up to 25Subcommands
to this command.
When a subcommand or subcommand group is added, the base command itself cannot be used. Thus usingSlashCommandData.addOptions(OptionData...)
andSlashCommandData.addSubcommands(SubcommandData...)
/SlashCommandData.addSubcommandGroups(SubcommandGroupData...)
for the same command, is not supported.Valid command layouts are as follows:
Having an option and subcommand simultaneously is not allowed.command |-- subcommand |__ subcommand group |__ subcommand command |__ subcommand group |__ subcommand command |-- option |__ option
- Specified by:
addSubcommands
in interfaceSlashCommandData
- Parameters:
subcommands
- The subcommands to add- Returns:
- The builder instance, for chaining
-
addSubcommandGroups
@Nonnull @CheckReturnValue CommandCreateAction addSubcommandGroups(@Nonnull SubcommandGroupData... groups) Description copied from interface:SlashCommandData
Add up to 25Subcommand-Groups
to this command.
When a subcommand or subcommand group is added, the base command itself cannot be used. Thus usingSlashCommandData.addOptions(OptionData...)
andSlashCommandData.addSubcommands(SubcommandData...)
/SlashCommandData.addSubcommandGroups(SubcommandGroupData...)
for the same command, is not supported.Valid command layouts are as follows:
Having an option and subcommand simultaneously is not allowed.command |-- subcommand |__ subcommand group |__ subcommand command |__ subcommand group |__ subcommand command |-- option |__ option
- Specified by:
addSubcommandGroups
in interfaceSlashCommandData
- Parameters:
groups
- The subcommand groups to add- Returns:
- The builder instance, for chaining
-
addSubcommandGroups
@Nonnull @CheckReturnValue default CommandCreateAction addSubcommandGroups(@Nonnull Collection<? extends SubcommandGroupData> groups) Description copied from interface:SlashCommandData
Add up to 25Subcommand-Groups
to this command.
When a subcommand or subcommand group is added, the base command itself cannot be used. Thus usingSlashCommandData.addOptions(OptionData...)
andSlashCommandData.addSubcommands(SubcommandData...)
/SlashCommandData.addSubcommandGroups(SubcommandGroupData...)
for the same command, is not supported.Valid command layouts are as follows:
Having an option and subcommand simultaneously is not allowed.command |-- subcommand |__ subcommand group |__ subcommand command |__ subcommand group |__ subcommand command |-- option |__ option
- Specified by:
addSubcommandGroups
in interfaceSlashCommandData
- Parameters:
groups
- The subcommand groups to add- Returns:
- The builder instance, for chaining
-
setDefaultPermissions
@Nonnull @CheckReturnValue CommandCreateAction setDefaultPermissions(@Nonnull DefaultMemberPermissions permission) Description copied from interface:CommandData
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.- Specified by:
setDefaultPermissions
in interfaceCommandData
- Specified by:
setDefaultPermissions
in interfaceSlashCommandData
- Parameters:
permission
-DefaultMemberPermissions
representing the default permissions of this command.- Returns:
- The builder instance, for chaining
- See Also:
-
setGuildOnly
Description copied from interface:CommandData
Sets whether this command is only usable in a guild (Default: false).
This only has an effect if this command is registered globally.- Specified by:
setGuildOnly
in interfaceCommandData
- Specified by:
setGuildOnly
in interfaceSlashCommandData
- Parameters:
guildOnly
- Whether to restrict this command to guilds- Returns:
- The builder instance, for chaining
-
setNSFW
Description copied from interface:CommandData
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.
- Specified by:
setNSFW
in interfaceCommandData
- Specified by:
setNSFW
in interfaceSlashCommandData
- Parameters:
nsfw
- True, to make this command nsfw- Returns:
- The builder instance, for chaining
- See Also:
-