- Type Parameters:
H
- The handler type of this command. The subtype(s) ofHandlers
used determine what methods of invocation are supported by this command. However, this type parameter is used only to facilitate type checking, with actual support being determined by the concrete type of the return value ofhandlers()
. See the description of that method for details.
Irrespective of whether the command it is used with is compatible with interactions or not, all values must be compatible with the Discord API specification for command parameters.
- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
Command.Builder<H extends @NonNull Handlers>
The default builder.static enum
The scopes that a command may be defined in. -
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
Default forcallable()
.static final boolean
Default fordeferReply()
.static final Group
Default forrequiredGroup()
(Groups.EVERYONE
).static final boolean
Default forinheritSettings()
.static final boolean
Default forinvokeParent()
.static final boolean
Default fornsfw()
.static final boolean
Default forrepliesDefaultPrivate()
.static final boolean
Default forrequireParentGroups()
.static final Command.Scope
Default forscope()
(Command.Scope.GLOBAL
).static final boolean
Default forskipGroupCheckOnInteraction()
.Pattern for valid command descriptions in the Discord API.Pattern for valid user/message command names in the Discord API.Pattern for valid slash command names in the Discord API. -
Method Summary
Modifier and TypeMethodDescriptiondefault Set<@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String>
aliases()
The aliases that may also invoke the command, when invoking through a message.default Set<Invocation>
The alias invocations that may also invoke the command.static <H extends @NonNull Handlers>
Command.Builder<H>builder()
Creates a new builder.static <H extends @NonNull Handlers>
Command.Builder<H>Creates a new builder initialized with the properties of the given command.default boolean
callable()
Whether this command can be invoked by a user.default boolean
Whether the initial reply to the command should be deferred, indicating to the user that a reply is pending.@MatchesRegex("(?Us)^.{1,100}+$") String
The description of the command.@MatchesRegex("(?U)^[ -_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String
The display name of the command.handlers()
The handlers to use for processing an invocation of the command.id()
The ID that uniquely identifies this command in the system.default boolean
Whether the command settings should be inherited from the parent command (ignoring the values provided by this command).static Command.Builder<InteractionHandlers>
Creates a builder for an interaction command.default Invocation
The invocation that executes this command.default boolean
Whether the parent command should be invoked before this command is invoked.static Command.Builder<MessageHandlers>
message()
Creates a builder for a message-only command.@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String
name()
The name of the command.default boolean
nsfw()
Whether this command can only be invoked in a NSFW channel.The command parameters, in the order that they should be provided by the user.default Invocation
parent()
The parent of the command.default boolean
Whether the replies sent by this command should be private by default (i.e.default Group
The group that a user must have access for in order to invoke this command.default boolean
Whether a user invoking this command must also have access to the groups necessary to invoke its parent command(s).default Command.Scope
scope()
The scope that the command is defined in.default boolean
Whether group access checking should be skipped when this command is invoked through an interaction.static Command.Builder<SlashHandlers>
slash()
Creates a builder for a slash-only command.static Command.Builder<TextHandlers>
text()
Creates a builder for a text (message and slash) command.default void
validate()
Validates that the command properties of this instance are valid.
-
Field Details
-
DEFAULT_SCOPE
Default forscope()
(Command.Scope.GLOBAL
). -
DEFAULT_CALLABLE
static final boolean DEFAULT_CALLABLEDefault forcallable()
.- See Also:
-
DEFAULT_GROUP
Default forrequiredGroup()
(Groups.EVERYONE
). -
DEFAULT_SKIP
static final boolean DEFAULT_SKIPDefault forskipGroupCheckOnInteraction()
.- See Also:
-
DEFAULT_REQUIRE_PARENT_GROUPS
static final boolean DEFAULT_REQUIRE_PARENT_GROUPSDefault forrequireParentGroups()
.- See Also:
-
DEFAULT_NSFW
static final boolean DEFAULT_NSFWDefault fornsfw()
.- See Also:
-
DEFAULT_PRIVATE
static final boolean DEFAULT_PRIVATEDefault forrepliesDefaultPrivate()
.- See Also:
-
DEFAULT_DEFER
static final boolean DEFAULT_DEFERDefault fordeferReply()
.- See Also:
-
DEFAULT_INHERIT
static final boolean DEFAULT_INHERITDefault forinheritSettings()
.- See Also:
-
DEFAULT_INVOKE_PARENT
static final boolean DEFAULT_INVOKE_PARENTDefault forinvokeParent()
.- See Also:
-
NAME_REGEX
Pattern for valid slash command names in the Discord API.- See Also:
-
DISPLAY_NAME_REGEX
Pattern for valid user/message command names in the Discord API.- See Also:
-
DESCRIPTION_REGEX
Pattern for valid command descriptions in the Discord API.- See Also:
-
-
Method Details
-
id
The ID that uniquely identifies this command in the system.- Returns:
- The command ID.
-
scope
The scope that the command is defined in.- Returns:
- The command scope.
- Implementation Requirements:
- The default value is
DEFAULT_SCOPE
.
-
callable
Whether this command can be invoked by a user.A non-callable command is usually used as a parent for other commands that should not be itself invoked.
Do note that slash commands cannot be invoked if they have children commands, and so in that case this parameter has no effect. This is a limitation from Discord itself.
- Returns:
true
if the command may be directly called by users.false
otherwise.- Implementation Requirements:
- The default value is true.
-
parent
The parent of the command.If the invocation returned by this is empty, this command has no parent, and is therefore a main command. Otherwise, it is a subcommand.
Note that a parent can only be specified by its
name
, not any aliases it may have (when supported). This implies that any command that may match the Invocation returned by this method through an alias is not considered a parent of this command.- Returns:
- The parent of the command.
- Implementation Requirements:
- The default is
the empty invocation
(e.g. no parent).
-
name
The name of the command.This is the name used to match the command internally and for accessing text-based commands (slash and text commands). It is provided to the Discord API for slash commands, but not for user and message commands (for that, see
displayName()
).- Returns:
- The name of the command.
-
invocation
The invocation that executes this command. -
aliases
@Pure @Default default Set<@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String> aliases()The aliases that may also invoke the command, when invoking through a message.These aliases are only relevant to handling invocations. They may not be used to specify the command as a parent.
Aliases must satisfy the same restrictions as the
name
.- Returns:
- The command aliases.
- API Note:
- This setting is only meaningful for message-based invocations. By extension, if the command does not support message invocations, this setting has no effect.
- Implementation Requirements:
- The default is an empty set.
-
aliasInvocations
The alias invocations that may also invoke the command.- Returns:
- The command aliases as invocations.
- See Also:
- API Note:
- This value is only meaningful for message-based invocations. By extension, if the command does not support message invocations, this setting has no effect.
- Implementation Requirements:
- The invocation is determined by appending each alias to the
parent
. Do not override this.
-
displayName
The display name of the command.This is displayed to the user in documentation-related functionality. For user and message commands, this is also the value provided to the Discord API as the command name instead of
name()
.- Returns:
- The display name of the command.
-
description
The description of the command.- Returns:
- The description of the command.
-
parameters
The command parameters, in the order that they should be provided by the user.All parameters that are marked as
required
must come before all parameters that aren't (optional parameters).- Returns:
- The command parameters.
- API Note:
- The restriction in parameter order is due to the fact that it would not make any sense to have an optional parameter before a required one. Since all parameters must be provided in sequence, that would effectively make the optional parameter required.
-
requiredGroup
The group that a user must have access for in order to invoke this command.Note that having access to a group is not necessarily the same as belonging to that group (although it is the basic threshold); the specific definition depends on the
AccessValidator
implementation used to verify access.For application commands, be aware that this is completely disjoint from Discord's own permission system, and so utilizing this feature may lead to user confusion due to discrepancies between the apparent configured permissions and the internal group checks. It is nonetheless left as an option for situations where the application should have control over who is allowed to run the command (instead of guild administrators), for example global debug commands that should be reserved for the developers, and for complex permissions beyond what Discord can support (for example, subcommand-specific access restrictions). Make sure that
group checking is not skipped
when doing this.To completely skip group checking on invocations made through application commands (possibly saving a few function calls in such cases), use
skipGroupCheckOnInteraction()
. It may also be useful in the case of commands that support both text and interactions, where group checking may be wanted only for the text case (where there is no built-in permission system through Discord).- Returns:
- The required group.
- Implementation Requirements:
- The default value is
DEFAULT_GROUP
.
-
skipGroupCheckOnInteraction
Whether group access checking should be skipped when this command is invoked through an interaction.- Returns:
- Whether group access checking should be skipped when this command is invoked through an interaction.
- See Also:
- API Note:
- This value is only meaningful for interaction-based invocations. By extension, if the command does not support interaction invocations, this setting has no effect.
- Implementation Requirements:
- The default value is true, as application commands should generally avoid clashing with user-set permissions unless necessary.
-
requireParentGroups
Whether a user invoking this command must also have access to the groups necessary to invoke its parent command(s).- Returns:
- Whether a user invoking this command must also have access to the groups required by its parents.
- See Also:
- API Note:
- This value is only meaningful for subcommands.
- Implementation Requirements:
- The default value is true.
-
nsfw
Whether this command can only be invoked in a NSFW channel.A private channel (if the
scope
of the command allows invocation in one) always satisfies this condition.Conversely, a guild channel that cannot be marked as NSFW (such as an announcement channel) never satisfies this condition.
- Returns:
- Whether this command can only be invoked in a NSFW channel.
- Implementation Requirements:
- The default value is false.
-
repliesDefaultPrivate
Whether the replies sent by this command should be private by default (i.e. unless specified otherwise on the individual reply).- Returns:
- Whether this command's responses should be private by default.
- See Also:
- API Note:
- The specific mechanism used for private replies may vary depending on how the command was invoked (message, slash command, etc).
- Implementation Requirements:
- The default value is false.
-
deferReply
Whether the initial reply to the command should be deferred, indicating to the user that a reply is pending.Note that whether the deferral is publicly visible or not is defined by the
default visibility of replies
. Note also that, if deferral is used, the visibility of the first reply will be set to the default to match the deferral, with the value ofCommandReplySpec.privately()
being ignored if set. Further replies are not affected.If using a deferral, it is expected that a reply will be sent at some point. It is an error to set this to
true
and not send any replies.- Returns:
- Whether this command's initial response is deferred.
- API Note:
- The specific mechanism used for deferral may vary depending on how the command was invoked (message, slash command, etc).
- Implementation Requirements:
- The default value is false.
-
inheritSettings
Whether the command settings should be inherited from the parent command (ignoring the values provided by this command).The settings are the values provided by the following methods:
- Returns:
- Whether settings should be inherited from the parent command.
- API Note:
- This value is only meaningful for subcommands.
- Implementation Requirements:
- The default value is false.
-
invokeParent
Whether the parent command should be invoked before this command is invoked.If the parent command may also define that its parent must be executed, and so on. Execution will start at the closest ancestor that sets this to false or does not have a parent (including itself).
The parent(s) will be invoked with the same context object, which means that a parent may pass objects to a child through the context. It also means that the parameters to this command must be compatible with all executed ancestors, which means that
- Any parameter that is defined in both this command and an executed parent (that is, has the same name) must be of the same type.
- Any parameter that is required in an executed parent must be defined in this command, and it must either be also required or have a default value.
- The order of shared parameters does not need to be the same or similar in any way.
If the parameters of this command are not compatible with those of any executed parent as defined above, an error will be triggered at execution time.
There are no compatibility requirements for ancestors that would not be executed as part of an execution of this command.
Naturally, this flag has no effect on a command with no parent.
- Returns:
- Whether this command's parent should be executed as part of an invocation.
- Implementation Requirements:
- The default value is false.
-
handlers
The handlers to use for processing an invocation of the command.Note that the subtype(s) of
Handlers
implemented by the returned instance determine what methods of invocation are supported by this command. For example, if it implements onlyMessageHandlers
, it will only support message commands; if it implements bothMessageHandlers
andSlashHandlers
, it will support both message commands and slash commands; and so on.Be careful that, while this interface does have a generic type parameter to constrain the allowed return type for this method, it is used only to facilitate type checking (especially internally). The invocation support is determined by the actual type of the instance returned by this method. That is, if this method returns an object that implements both
MessageHandlers
andSlashHandlers
, this command will support both message and slash commands, even if this instance is created as of typeCommand<MessageHandlers>
. There is no way around this due to the nature of type erasure.- Returns:
- The handler.
-
validate
Validates that the command properties of this instance are valid.- Throws:
IllegalArgumentException
- if any of properties are invalid.NullPointerException
- if anull
value was found where not allowed.- See Also:
-
builder
Creates a new builder.- Type Parameters:
H
- The handler type.- Returns:
- The builder.
-
builder
Creates a new builder initialized with the properties of the given command.- Type Parameters:
H
- The argument type.- Parameters:
base
- The base instance to copy.- Returns:
- The builder.
-
message
Creates a builder for a message-only command.- Returns:
- The builder.
- API Note:
- Use to force the type argument when it cannot be inferred.
-
slash
Creates a builder for a slash-only command.- Returns:
- The builder.
- API Note:
- Use to force the type argument when it cannot be inferred.
-
text
Creates a builder for a text (message and slash) command.- Returns:
- The builder.
- API Note:
- Use to force the type argument when it cannot be inferred.
-
interaction
Creates a builder for an interaction command.- Returns:
- The builder.
- API Note:
- Use to force the type argument when it cannot be inferred.
-