Class Command
- java.lang.Object
-
- net.dv8tion.jda.api.interactions.commands.Command
-
- All Implemented Interfaces:
ISnowflake
public class Command extends java.lang.Object implements ISnowflake
Represents a Discord slash-command.
This can be used to edit or delete the command.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommand.ChoicePredefined choice used for options.static classCommand.OptionAn Option for a command.static classCommand.SubcommandAn Subcommand for a command.static classCommand.SubcommandGroupAn Subcommand Group for a command.
-
Constructor Summary
Constructors Constructor Description Command(net.dv8tion.jda.internal.JDAImpl api, Guild guild, DataObject json)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RestAction<java.lang.Void>delete()Delete this command.CommandEditActioneditCommand()Edit this command.booleanequals(java.lang.Object obj)java.lang.StringgetApplicationId()The id of the application this command belongs to.longgetApplicationIdLong()The id of the application this command belongs to.java.lang.StringgetDescription()The description of this command.longgetIdLong()The Snowflake id of this entity.JDAgetJDA()Returns theJDAinstance of this Commandjava.lang.StringgetName()The name of this command.java.util.List<Command.Option>getOptions()TheOptionsof this command.java.util.List<Command.SubcommandGroup>getSubcommandGroups()TheSubcommandGroupsof this command.java.util.List<Command.Subcommand>getSubcommands()TheSubcommandsof this command.java.time.OffsetDateTimegetTimeModified()The time this command was updated last.longgetVersion()The version of this command.inthashCode()booleanisDefaultEnabled()Whether this command is enabled for everyone by default.RestAction<java.util.List<CommandPrivilege>>retrievePrivileges(Guild guild)Retrieves theCommandPrivilegesfor this command.java.lang.StringtoString()RestAction<java.util.List<CommandPrivilege>>updatePrivileges(Guild guild, java.util.Collection<? extends CommandPrivilege> privileges)Updates the list ofCommandPrivilegesfor this command.RestAction<java.util.List<CommandPrivilege>>updatePrivileges(Guild guild, CommandPrivilege... privileges)Updates the list ofCommandPrivilegesfor this command.-
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getTimeCreated
-
-
-
-
Constructor Detail
-
Command
public Command(net.dv8tion.jda.internal.JDAImpl api, Guild guild, DataObject json)
-
-
Method Detail
-
delete
@Nonnull @CheckReturnValue public RestAction<java.lang.Void> delete()
Delete this command.
If this is a global command it may take up to 1 hour to vanish from all clients.- Returns:
RestAction- Throws:
java.lang.IllegalStateException- If this command is not owned by this bot
-
editCommand
@Nonnull @CheckReturnValue public CommandEditAction editCommand()
Edit this command.
This can be used to change the command attributes such as name or description.- Returns:
CommandEditAction- Throws:
java.lang.IllegalStateException- If this command is not owned by this bot
-
retrievePrivileges
@Nonnull @CheckReturnValue public RestAction<java.util.List<CommandPrivilege>> retrievePrivileges(@Nonnull Guild guild)
Retrieves theCommandPrivilegesfor this command.
This is a shortcut forGuild.retrieveCommandPrivilegesById(String).These privileges are used to restrict who can use commands through Role/User whitelists/blacklists.
If there is no command with the provided ID, this RestAction fails with
ErrorResponse.UNKNOWN_COMMAND- Parameters:
guild- The target guild from which to retrieve the privileges- Returns:
RestAction- Type:ListofCommandPrivilege- Throws:
java.lang.IllegalArgumentException- If the guild is null
-
updatePrivileges
@Nonnull @CheckReturnValue public RestAction<java.util.List<CommandPrivilege>> updatePrivileges(@Nonnull Guild guild, @Nonnull java.util.Collection<? extends CommandPrivilege> privileges)
Updates the list ofCommandPrivilegesfor this command.These privileges are used to restrict who can use commands through Role/User whitelists/blacklists.
If there is no command with the provided ID, this RestAction fails with
ErrorResponse.UNKNOWN_COMMAND- Parameters:
guild- The target guild from which to update the privilegesprivileges- Complete list ofCommandPrivilegesfor this command- Returns:
RestAction- Type:ListorCommandPrivilegeThe updated list of privileges for this command.- Throws:
java.lang.IllegalArgumentException- If null is providedjava.lang.IllegalStateException- If this command is not owned by this bot
-
updatePrivileges
@Nonnull @CheckReturnValue public RestAction<java.util.List<CommandPrivilege>> updatePrivileges(@Nonnull Guild guild, @Nonnull CommandPrivilege... privileges)
Updates the list ofCommandPrivilegesfor this command.These privileges are used to restrict who can use commands through Role/User whitelists/blacklists.
If there is no command with the provided ID, this RestAction fails with
ErrorResponse.UNKNOWN_COMMAND- Parameters:
guild- The target guild from which to update the privilegesprivileges- Complete list ofCommandPrivilegesfor this command- Returns:
RestAction- Type:ListorCommandPrivilegeThe updated list of privileges for this command.- Throws:
java.lang.IllegalArgumentException- If null is providedjava.lang.IllegalStateException- If this command is not owned by this bot
-
getJDA
@Nonnull public JDA getJDA()
Returns theJDAinstance of this Command- Returns:
- the corresponding JDA instance
-
getName
@Nonnull public java.lang.String getName()
The name of this command.- Returns:
- The name
-
getDescription
@Nonnull public java.lang.String getDescription()
The description of this command.- Returns:
- The description
-
isDefaultEnabled
public boolean isDefaultEnabled()
Whether this command is enabled for everyone by default.- Returns:
- True, if everyone can use this command by default.
-
getOptions
@Nonnull public java.util.List<Command.Option> getOptions()
TheOptionsof this command.- Returns:
- Immutable list of command options
-
getSubcommands
@Nonnull public java.util.List<Command.Subcommand> getSubcommands()
TheSubcommandsof this command.- Returns:
- Immutable list of subcommands
-
getSubcommandGroups
@Nonnull public java.util.List<Command.SubcommandGroup> getSubcommandGroups()
TheSubcommandGroupsof this command.- Returns:
- Immutable list of subcommand groups
-
getApplicationIdLong
public long getApplicationIdLong()
The id of the application this command belongs to.- Returns:
- The application id
-
getApplicationId
@Nonnull public java.lang.String getApplicationId()
The id of the application this command belongs to.- Returns:
- The application id
-
getVersion
public long getVersion()
The version of this command.
This changes when a command is updated throughupsertCommand,updateCommands, oreditCommandById
Useful for checking if command cache is outdated- Returns:
- The version of the command as a snowflake id.
- See Also:
getTimeModified()
-
getTimeModified
@Nonnull public java.time.OffsetDateTime getTimeModified()
The time this command was updated last.- Returns:
- Time this command was updated last.
- See Also:
getVersion()
-
getIdLong
public long getIdLong()
Description copied from interface:ISnowflakeThe Snowflake id of this entity. This is unique to every entity and will never change.- Specified by:
getIdLongin interfaceISnowflake- Returns:
- Long containing the Id.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-