Interface CommandCreateAction
-
- All Superinterfaces:
CommandData
,RestAction<Command>
,SerializableData
,SlashCommandData
public interface CommandCreateAction extends RestAction<Command>, SlashCommandData
SpecializedRestAction
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.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description CommandCreateAction
addCheck(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.CommandCreateAction
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.CommandCreateAction
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.CommandCreateAction
addSubcommands(SubcommandData... subcommands)
Add up to 25Subcommands
to this command.CommandCreateAction
deadline(long timestamp)
Similar toRestAction.timeout(long, TimeUnit)
but schedules a deadline at which the request has to be completed.CommandCreateAction
setCheck(BooleanSupplier checks)
Sets the last-second checks before finally executing the http request in the queue.CommandCreateAction
setDefaultEnabled(boolean enabled)
Whether this command is available to everyone by default.CommandCreateAction
setDescription(String description)
Configure the descriptionCommandCreateAction
setName(String name)
Configure the command name.CommandCreateAction
timeout(long timeout, TimeUnit unit)
Timeout for this RestAction instance.-
Methods inherited from interface net.dv8tion.jda.api.interactions.commands.build.CommandData
getName, getType, isDefaultEnabled
-
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, 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, getOptions, getSubcommandGroups, getSubcommands
-
-
-
-
Method Detail
-
setCheck
@Nonnull CommandCreateAction setCheck(@Nullable BooleanSupplier checks)
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:
RestAction.getCheck()
,RestAction.addCheck(BooleanSupplier)
-
addCheck
@Nonnull CommandCreateAction addCheck(@Nonnull BooleanSupplier checks)
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:
RestAction.setCheck(BooleanSupplier)
-
timeout
@Nonnull CommandCreateAction timeout(long timeout, @Nonnull TimeUnit unit)
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:
RestAction.setDefaultTimeout(long, TimeUnit)
-
deadline
@Nonnull @CheckReturnValue CommandCreateAction deadline(long timestamp)
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:
RestAction.timeout(long, TimeUnit)
,RestAction.setDefaultTimeout(long, TimeUnit)
-
setDefaultEnabled
@Nonnull @CheckReturnValue CommandCreateAction setDefaultEnabled(boolean enabled)
Description copied from interface:CommandData
Whether this command is available to everyone by default.
If this is disabled, you need to explicitly whitelist users and roles per guild.You can use
CommandPrivilege
to enable or disable this command per guild for roles and members of the guild. SeeCommand.updatePrivileges(Guild, CommandPrivilege...)
andGuild.updateCommandPrivileges(Map)
.- Specified by:
setDefaultEnabled
in interfaceCommandData
- Specified by:
setDefaultEnabled
in interfaceSlashCommandData
- Parameters:
enabled
- True, if this command is enabled by default for everyone. (Default: true)- Returns:
- The builder instance, for chaining
-
setName
@Nonnull @CheckReturnValue CommandCreateAction setName(@Nonnull String name)
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
-
setDescription
@Nonnull @CheckReturnValue CommandCreateAction setDescription(@Nonnull String description)
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
-
addOptions
@Nonnull @CheckReturnValue CommandCreateAction addOptions(@Nonnull 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
-
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.- 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.- 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.- 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.- Specified by:
addSubcommandGroups
in interfaceSlashCommandData
- Parameters:
groups
- The subcommand groups to add- Returns:
- The builder instance, for chaining
-
-