Class RestrictedCommand
java.lang.Object
xyz.dynxsty.dih4jda.interactions.commands.RestrictedCommand
- Direct Known Subclasses:
ApplicationCommand
Represents a basic command.
- Since:
- v1.6
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Model class which represents a single command cooldown. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
applyCooldown
(long userId, Instant nextUse) Manually applies a cooldown for the specified user id.
Command Cooldowns DO NOT persist between sessions!Returns theDuration
the user has to wait between command executions.Long[]
The required guilds the command can be executed in.final net.dv8tion.jda.api.Permission[]
The requiredPermission
theUser
needs to execute the command.final Long[]
TheRole
s that are required to execute the command.final Long[]
The user ids from theUser
that are allowed to execute the command.boolean
hasCooldown
(long userId) Returns whether the command can be used by the specified user.
Command Cooldowns DO NOT persist between sessions!retrieveCooldown
(long userId) Gets thetime
the specified user can execute this command again.void
setCommandCooldown
(Duration commandCooldown) Allows to set a cooldown for this command.final void
setRequiredGuilds
(Long... guilds) Allows to require a set ofGuild
s only in which the command can get executed.final void
setRequiredPermissions
(net.dv8tion.jda.api.Permission... permissions) Allows to require a set ofPermission
s which are needed to execute the corresponding command.final void
setRequiredRoles
(Long... roles) Allows to require a set ofLong
s (role Ids) which are able to execute the corresponding command.final void
setRequiredUsers
(Long... users) Allows to require a set ofLong
s (user Ids) which are able to execute the corresponding command.
-
Constructor Details
-
RestrictedCommand
public RestrictedCommand()Creates a default instance.
-
-
Method Details
-
setRequiredGuilds
Allows to require a set ofGuild
s only in which the command can get executed.- Parameters:
guilds
- ALong
array, containting the guild ids.
-
getRequiredGuilds
The required guilds the command can be executed in.- Returns:
- The
Long
array containing the guild ids.
-
getRequiredPermissions
@Nonnull public final net.dv8tion.jda.api.Permission[] getRequiredPermissions()The requiredPermission
theUser
needs to execute the command.- Returns:
- the
Permission
.
-
setRequiredPermissions
public final void setRequiredPermissions(@Nonnull net.dv8tion.jda.api.Permission... permissions) Allows to require a set ofPermission
s which are needed to execute the corresponding command.- Parameters:
permissions
- The set ofPermission
s.
-
getRequiredUsers
The user ids from theUser
that are allowed to execute the command.- Returns:
- The
Long
array containing the user ids.
-
setRequiredUsers
Allows to require a set ofLong
s (user Ids) which are able to execute the corresponding command.- Parameters:
users
- TheUser
ids as anLong
array.
-
getRequiredRoles
TheRole
s that are required to execute the command.- Returns:
- The
Long
array containing the role ids.
-
setRequiredRoles
Allows to require a set ofLong
s (role Ids) which are able to execute the corresponding command.- Parameters:
roles
- TheRole
ids as anLong
array.
-
setCommandCooldown
Allows to set a cooldown for this command. The user has to wait the providedDuration
until they can execute this command again. If the user executes the command while they're on cooldown, theCommandCooldownEvent
is fired.
Command Cooldowns DO NOT persist between sessions!- Parameters:
commandCooldown
- TheDuration
the user has to wait between command executions.
-
getCommandCooldown
Returns theDuration
the user has to wait between command executions.- Returns:
- The
Duration
. - See Also:
-
applyCooldown
Manually applies a cooldown for the specified user id.
Command Cooldowns DO NOT persist between sessions!- Parameters:
userId
- The targets' user id.nextUse
- TheInstant
that marks the time the command can be used again.
-
retrieveCooldown
Gets thetime
the specified user can execute this command again. If the user has not executed the command yet, this will return aRestrictedCommand.Cooldown
with both the nextUse and the lastUse ofInstant.EPOCH
instead.- Parameters:
userId
- The targets' user id.- Returns:
- The
Instant
that marks the time the command can be used again.
-
hasCooldown
public boolean hasCooldown(long userId) Returns whether the command can be used by the specified user.
Command Cooldowns DO NOT persist between sessions!- Parameters:
userId
- The targets' user id.- Returns:
- Whether the command can be executed.
-