Class CommandCreateActionImpl
- All Implemented Interfaces:
CommandData
,SlashCommandData
,RestAction<Command>
,CommandCreateAction
,SerializableData
-
Field Summary
Fields inherited from class net.dv8tion.jda.internal.requests.RestActionImpl
LOG
Fields inherited from interface net.dv8tion.jda.api.interactions.commands.build.CommandData
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH, MAX_OPTIONS
-
Constructor Summary
ConstructorsConstructorDescriptionCommandCreateActionImpl
(Guild guild, CommandDataImpl command) CommandCreateActionImpl
(JDAImpl api, CommandDataImpl command) -
Method Summary
Modifier and TypeMethodDescriptionaddCheck
(BooleanSupplier checks) Shortcut forsetCheck(() -> getCheck().getAsBoolean() && checks.getAsBoolean())
.addOptions
(OptionData... options) Adds up to 25 options to this command.addSubcommandGroups
(SubcommandGroupData... group) Add up to 25Subcommand-Groups
to this command.addSubcommands
(SubcommandData... subcommand) 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.okhttp3.RequestBody
The contexts in which this command can be used.Gets theDefaultMemberPermissions
of this command.The configured descriptionThe localizations of this command's description forvarious languages
.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
.The options for this command.TheSubcommand Groups
in this command.TheSubcommands
in this command.getType()
TheCommand.Type
boolean
isNSFW()
Whether this command should only be usable in NSFW (age-restricted) channelsboolean
removeOptions
(Predicate<? super OptionData> condition) Removes all options that evaluate totrue
under the providedcondition
.boolean
removeSubcommandGroups
(Predicate<? super SubcommandGroupData> condition) Removes all subcommand groups that evaluate totrue
under the providedcondition
.boolean
removeSubcommands
(Predicate<? super SubcommandData> condition) Removes all subcommands that evaluate totrue
under the providedcondition
.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).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.setIntegrationTypes
(Collection<IntegrationType> integrationTypes) Sets the integration types on which this command can be installed on (Default: Guilds).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.toData()
SerializedDataObject
for this object.Methods inherited from class net.dv8tion.jda.internal.requests.RestActionImpl
complete, getCheck, getDefaultFailure, getDefaultSuccess, getDefaultTimeout, getJDA, handleResponse, isPassContext, priority, queue, setDefaultFailure, setDefaultSuccess, setDefaultTimeout, setErrorMapper, setPassContext, submit
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.dv8tion.jda.api.requests.restaction.CommandCreateAction
addOption, addOption, addOption, addOptions, addSubcommandGroups, addSubcommands, setContexts, setIntegrationTypes
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.interactions.commands.build.SlashCommandData
removeOptionByName, removeSubcommandByName, removeSubcommandGroupByName
-
Constructor Details
-
CommandCreateActionImpl
-
CommandCreateActionImpl
-
-
Method Details
-
addCheck
Description copied from interface:RestAction
Shortcut forsetCheck(() -> getCheck().getAsBoolean() && checks.getAsBoolean())
.- Specified by:
addCheck
in interfaceCommandCreateAction
- Specified by:
addCheck
in interfaceRestAction<Command>
- Parameters:
checks
- Other checks to run- Returns:
- The current RestAction for chaining convenience
- See Also:
-
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 interfaceCommandCreateAction
- Specified by:
setCheck
in interfaceRestAction<Command>
- Overrides:
setCheck
in classRestActionImpl<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:
-
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 interfaceCommandCreateAction
- Specified by:
deadline
in interfaceRestAction<Command>
- Overrides:
deadline
in classRestActionImpl<Command>
- Parameters:
timestamp
- Millisecond timestamp at which the request will timeout- Returns:
- The same RestAction with the applied deadline
- See Also:
-
setDefaultPermissions
@Nonnull public 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 interfaceCommandCreateAction
- 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:
-
setContexts
@Nonnull public CommandCreateAction setContexts(@Nonnull Collection<InteractionContextType> contexts) Description copied from interface:CommandData
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.- Specified by:
setContexts
in interfaceCommandCreateAction
- Specified by:
setContexts
in interfaceCommandData
- Specified by:
setContexts
in interfaceSlashCommandData
- Parameters:
contexts
- The contexts in which this command can be used- Returns:
- The builder instance, for chaining
-
setIntegrationTypes
@Nonnull public CommandCreateAction setIntegrationTypes(@Nonnull Collection<IntegrationType> integrationTypes) Description copied from interface:CommandData
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.- Specified by:
setIntegrationTypes
in interfaceCommandCreateAction
- Specified by:
setIntegrationTypes
in interfaceCommandData
- Specified by:
setIntegrationTypes
in 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: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 interfaceCommandCreateAction
- 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:
-
setLocalizationFunction
@Nonnull public 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 interfaceCommandCreateAction
- Specified by:
setLocalizationFunction
in interfaceCommandData
- Specified by:
setLocalizationFunction
in interfaceSlashCommandData
- Parameters:
localizationFunction
- The localization function- Returns:
- The builder instance, for chaining
-
getName
Description copied from interface:CommandData
The current command name- Specified by:
getName
in interfaceCommandData
- Returns:
- The command name
-
getNameLocalizations
Description copied from interface:CommandData
The localizations of this command's name forvarious languages
.- Specified by:
getNameLocalizations
in interfaceCommandData
- Returns:
- The
LocalizationMap
containing the mapping fromDiscordLocale
to the localized name
-
getType
Description copied from interface:CommandData
TheCommand.Type
- Specified by:
getType
in interfaceCommandData
- Returns:
- The
Command.Type
-
getDefaultPermissions
Description copied from interface:CommandData
Gets theDefaultMemberPermissions
of this command.
If no permissions have been set, this returnsDefaultMemberPermissions.ENABLED
.- Specified by:
getDefaultPermissions
in interfaceCommandData
- Returns:
- DefaultMemberPermissions of this command.
- See Also:
-
getContexts
Description copied from interface:CommandData
The contexts in which this command can be used.- Specified by:
getContexts
in interfaceCommandData
- Returns:
- The contexts in which this command can be used
-
getIntegrationTypes
Description copied from interface:CommandData
Gets the integration types on which this command can be installed on.- Specified by:
getIntegrationTypes
in interfaceCommandData
- Returns:
- The integration types on which this command can be installed on
-
isNSFW
public boolean isNSFW()Description copied from interface:CommandData
Whether this command should only be usable in NSFW (age-restricted) channels- Specified by:
isNSFW
in interfaceCommandData
- Returns:
- True, if this command is restricted to NSFW channels
- 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 interfaceCommandCreateAction
- 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:
-
setName
Description copied from interface:CommandData
Configure the command name.- Specified by:
setName
in interfaceCommandCreateAction
- 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 public 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 interfaceCommandCreateAction
- 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
Description copied from interface:CommandData
Sets multiplelanguage-specific
localizations of this command's name.- Specified by:
setNameLocalizations
in interfaceCommandCreateAction
- 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 interfaceCommandCreateAction
- Specified by:
setDescription
in interfaceSlashCommandData
- Parameters:
description
- The description, 1-100 characters- Returns:
- The builder, for chaining
-
setDescriptionLocalization
@Nonnull public 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 interfaceCommandCreateAction
- 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 public 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 interfaceCommandCreateAction
- Specified by:
setDescriptionLocalizations
in interfaceSlashCommandData
- Parameters:
map
- The map from which to transfer the translated descriptions- Returns:
- This builder instance, for chaining
-
getDescription
Description copied from interface:SlashCommandData
The configured description- Specified by:
getDescription
in interfaceSlashCommandData
- Returns:
- The description
-
getDescriptionLocalizations
Description copied from interface:SlashCommandData
The localizations of this command's description forvarious languages
.- Specified by:
getDescriptionLocalizations
in interfaceSlashCommandData
- Returns:
- The
LocalizationMap
containing the mapping fromDiscordLocale
to the localized description
-
removeOptions
Description copied from interface:SlashCommandData
Removes all options that evaluate totrue
under the providedcondition
.
This will not affect options within subcommands. UseSubcommandData.removeOptions(Predicate)
instead.Example: Remove all options
command.removeOptions(option -> true);
Example: Remove all options that are required
command.removeOptions(option -> option.isRequired());
- Specified by:
removeOptions
in interfaceSlashCommandData
- Parameters:
condition
- The removal condition (must not throw)- Returns:
- True, if any options were removed
-
removeSubcommands
Description copied from interface:SlashCommandData
Removes all subcommands that evaluate totrue
under the providedcondition
.
This will not apply to subcommands within subcommand groups. UseSubcommandGroupData.removeSubcommand(Predicate)
instead.Example: Remove all subcommands
command.removeSubcommands(subcommand -> true);
- Specified by:
removeSubcommands
in interfaceSlashCommandData
- Parameters:
condition
- The removal condition (must not throw)- Returns:
- True, if any subcommands were removed
-
removeSubcommandGroups
Description copied from interface:SlashCommandData
Removes all subcommand groups that evaluate totrue
under the providedcondition
.Example: Remove all subcommand groups
command.removeSubcommandGroups(group -> true);
- Specified by:
removeSubcommandGroups
in interfaceSlashCommandData
- Parameters:
condition
- The removal condition (must not throw)- Returns:
- True, if any subcommand groups were removed
-
getSubcommands
Description copied from interface:SlashCommandData
TheSubcommands
in this command.- Specified by:
getSubcommands
in interfaceSlashCommandData
- Returns:
- Immutable list of
SubcommandData
-
getSubcommandGroups
Description copied from interface:SlashCommandData
TheSubcommand Groups
in this command.- Specified by:
getSubcommandGroups
in interfaceSlashCommandData
- Returns:
- Immutable list of
SubcommandGroupData
-
getOptions
Description copied from interface:SlashCommandData
The options for this command.- Specified by:
getOptions
in interfaceSlashCommandData
- Returns:
- Immutable list of
OptionData
-
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 interfaceCommandCreateAction
- Specified by:
addOptions
in interfaceSlashCommandData
- Parameters:
options
- TheOptions
to add- Returns:
- The builder instance, for chaining
-
addSubcommands
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 interfaceCommandCreateAction
- Specified by:
addSubcommands
in interfaceSlashCommandData
- Parameters:
subcommand
- The subcommands to add- Returns:
- The builder instance, for chaining
-
addSubcommandGroups
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 interfaceCommandCreateAction
- Specified by:
addSubcommandGroups
in interfaceSlashCommandData
- Parameters:
group
- The subcommand groups to add- Returns:
- The builder instance, for chaining
-
finalizeData
public okhttp3.RequestBody finalizeData() -
toData
Description copied from interface:SerializableData
SerializedDataObject
for this object.- Specified by:
toData
in interfaceSerializableData
- Returns:
DataObject
-