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 CommandCreateActionaddOption(OptionType type, String name, String description) Adds an option to this command.default CommandCreateActionaddOption(OptionType type, String name, String description, boolean required) Adds an option to this command.default CommandCreateActionaddOption(OptionType type, String name, String description, boolean required, boolean autoComplete) Adds an option to this command.default CommandCreateActionaddOptions(Collection<? extends OptionData> options) Adds up to 25 options to this command.addOptions(OptionData... options) Adds up to 25 options to this command.default CommandCreateActionaddSubcommandGroups(Collection<? extends SubcommandGroupData> groups) Add up to 25Subcommand-Groupsto this command.addSubcommandGroups(SubcommandGroupData... groups) Add up to 25Subcommand-Groupsto this command.default CommandCreateActionaddSubcommands(Collection<? extends SubcommandData> subcommands) Add up to 25Subcommandsto this command.addSubcommands(SubcommandData... subcommands) Add up to 25Subcommandsto 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.setContexts(Collection<InteractionContextType> contexts) Sets the contexts in which this command can be used (Default: Guild and Bot DMs).default CommandCreateActionsetContexts(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.setDescription(String description) Configure the descriptionsetDescriptionLocalization(DiscordLocale locale, String description) Sets alanguage-specificlocalizations of this command's description.Sets multiplelanguage-specificlocalizations of this command's description.setIntegrationTypes(Collection<IntegrationType> integrationTypes) Sets the integration types on which this command can be installed on (Default: Guilds).default CommandCreateActionsetIntegrationTypes(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.Timeout for this RestAction instance.Methods inherited from interface net.dv8tion.jda.api.interactions.commands.build.CommandData
getContexts, getDefaultPermissions, getIntegrationTypes, getName, getNameLocalizations, getType, isNSFWMethods 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, zipMethods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toDataMethods 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:RestActionSets the last-second checks before finally executing the http request in the queue.
If the provided supplier evaluates tofalseor 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:
setCheckin interfaceRestAction<Command>- Parameters:
checks- The checks to run before executing the request, ornullto run no checks- Returns:
- The current RestAction for chaining convenience
- See Also:
-
addCheck
Description copied from interface:RestActionShortcut forsetCheck(() -> getCheck().getAsBoolean() && checks.getAsBoolean()).- Specified by:
addCheckin interfaceRestAction<Command>- Parameters:
checks- Other checks to run- Returns:
- The current RestAction for chaining convenience
- See Also:
-
timeout
Description copied from interface:RestActionTimeout 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:
timeoutin interfaceRestAction<Command>- Parameters:
timeout- The timeout to useunit-Unitfor the timeout value- Returns:
- The same RestAction instance with the applied timeout
- See Also:
-
deadline
Description copied from interface:RestActionSimilar 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:
deadlinein 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:CommandDataSets theLocalizationFunctionfor this command
This enables you to have the entirety of this command to be localized.- Specified by:
setLocalizationFunctionin interfaceCommandData- Specified by:
setLocalizationFunctionin interfaceSlashCommandData- Parameters:
localizationFunction- The localization function- Returns:
- The builder instance, for chaining
-
setName
Description copied from interface:CommandDataConfigure the command name.- Specified by:
setNamein interfaceCommandData- Specified by:
setNamein 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:CommandDataSets alanguage-specificlocalization of this command's name.- Specified by:
setNameLocalizationin interfaceCommandData- Specified by:
setNameLocalizationin 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:CommandDataSets multiplelanguage-specificlocalizations of this command's name.- Specified by:
setNameLocalizationsin interfaceCommandData- Specified by:
setNameLocalizationsin interfaceSlashCommandData- Parameters:
map- The map from which to transfer the translated names- Returns:
- This builder instance, for chaining
-
setDescription
Description copied from interface:SlashCommandDataConfigure the description- Specified by:
setDescriptionin 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:SlashCommandDataSets alanguage-specificlocalizations of this command's description.- Specified by:
setDescriptionLocalizationin 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:SlashCommandDataSets multiplelanguage-specificlocalizations of this command's description.- Specified by:
setDescriptionLocalizationsin interfaceSlashCommandData- Parameters:
map- The map from which to transfer the translated descriptions- Returns:
- This builder instance, for chaining
-
addOptions
Description copied from interface:SlashCommandDataAdds up to 25 options to this command.Required options must be added before non-required options!
- Specified by:
addOptionsin interfaceSlashCommandData- Parameters:
options- TheOptionsto add- Returns:
- The builder instance, for chaining
-
addOptions
@Nonnull @CheckReturnValue default CommandCreateAction addOptions(@Nonnull Collection<? extends OptionData> options) Description copied from interface:SlashCommandDataAdds up to 25 options to this command.Required options must be added before non-required options!
- Specified by:
addOptionsin interfaceSlashCommandData- Parameters:
options- TheOptionsto 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:SlashCommandDataAdds an option to this command.Required options must be added before non-required options!
- Specified by:
addOptionin interfaceSlashCommandData- Parameters:
type- TheOptionTypename- 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:SlashCommandDataAdds an option to this command.Required options must be added before non-required options!
- Specified by:
addOptionin interfaceSlashCommandData- Parameters:
type- TheOptionTypename- 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:SlashCommandDataAdds 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:
addOptionin interfaceSlashCommandData- Parameters:
type- TheOptionTypename- 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:SlashCommandDataAdd up to 25Subcommandsto 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:
addSubcommandsin 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:SlashCommandDataAdd up to 25Subcommandsto 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:
addSubcommandsin 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:SlashCommandDataAdd up to 25Subcommand-Groupsto 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:
addSubcommandGroupsin 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:SlashCommandDataAdd up to 25Subcommand-Groupsto 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:
addSubcommandGroupsin 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:CommandDataSets 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.- Specified by:
setDefaultPermissionsin interfaceCommandData- Specified by:
setDefaultPermissionsin interfaceSlashCommandData- Parameters:
permission-DefaultMemberPermissionsrepresenting the default permissions of this command.- Returns:
- The builder instance, for chaining
- See Also:
-
setContexts
@Nonnull @CheckReturnValue default CommandCreateAction setContexts(@Nonnull InteractionContextType... contexts) Description copied from interface:CommandDataSets 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.- Specified by:
setContextsin interfaceCommandData- Specified by:
setContextsin interfaceSlashCommandData- Parameters:
contexts- The contexts in which this command can be used- Returns:
- The builder instance, for chaining
-
setContexts
@Nonnull @CheckReturnValue CommandCreateAction setContexts(@Nonnull Collection<InteractionContextType> contexts) Description copied from interface:CommandDataSets 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.- Specified by:
setContextsin interfaceCommandData- Specified by:
setContextsin interfaceSlashCommandData- Parameters:
contexts- The contexts in which this command can be used- Returns:
- The builder instance, for chaining
-
setIntegrationTypes
@Nonnull @CheckReturnValue default CommandCreateAction setIntegrationTypes(@Nonnull IntegrationType... integrationTypes) Description copied from interface:CommandDataSets the integration types on which this command can be installed on (Default: Guilds).
This only has an effect if this command is registered globally.- Specified by:
setIntegrationTypesin interfaceCommandData- Specified by:
setIntegrationTypesin interfaceSlashCommandData- Parameters:
integrationTypes- The integration types on which this command can be installed on- Returns:
- The builder instance, for chaining
-
setIntegrationTypes
@Nonnull @CheckReturnValue CommandCreateAction setIntegrationTypes(@Nonnull Collection<IntegrationType> integrationTypes) Description copied from interface:CommandDataSets the integration types on which this command can be installed on (Default: Guilds).
This only has an effect if this command is registered globally.- Specified by:
setIntegrationTypesin interfaceCommandData- Specified by:
setIntegrationTypesin interfaceSlashCommandData- Parameters:
integrationTypes- The integration types on which this command can be installed on- Returns:
- The builder instance, for chaining
-
setNSFW
Description copied from interface:CommandDataSets 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:
setNSFWin interfaceCommandData- Specified by:
setNSFWin interfaceSlashCommandData- Parameters:
nsfw- True, to make this command nsfw- Returns:
- The builder instance, for chaining
- See Also:
-