public abstract class Command extends Object implements ICommand, PermissionsName
NAME| Constructor and Description |
|---|
Command(@NotNull String name,
@NotNull String group,
String description,
IArgument... args)
Creates a new Command Object.
|
| Modifier and Type | Method and Description |
|---|---|
protected Command |
addAliases(String... aliases)
Add alternative names to call this command.
|
protected Command |
addClientPermissions(net.dv8tion.jda.api.Permission... permissions)
Add Discord Permissions required by the bot in order to run this command.
|
protected Command |
addExample(String example)
Add a usage example to display in help command.
|
protected Command |
addExamples(String... example)
Add multiple usage examples to display in help command.
|
protected Command |
addMemberPermissions(net.dv8tion.jda.api.Permission... permissions)
Add Discord Permissions required by the user in order to run this command.
|
@NotNull String |
anyUsage(net.dv8tion.jda.api.events.Event event)
Generates example usages of the command.
|
protected @Nullable String |
checkClientPermissions(net.dv8tion.jda.api.events.Event event)
Check if the Client has the required permissions to run this command.
|
protected @Nullable String |
checkMemberPermissions(net.dv8tion.jda.api.events.Event event)
Check if the User has the required permissions to run this command.
|
String |
checkPermissions(net.dv8tion.jda.api.events.Event event)
Check if the user has permission to run this command, and to run it in the current channel.
|
List<String> |
getAliases()
Get a list of alternative names to call this command.
|
IArgument |
getArgument(String name)
Get a specific argument by its name.
|
List<IArgument> |
getArguments()
Get a list of arguments expected by this command.
|
List<net.dv8tion.jda.api.Permission> |
getClientPermissions()
Get the list of Permission required by the bot in the server to execute this command.
|
String |
getDescription()
Get the command's short description.
|
String |
getDescription(net.dv8tion.jda.api.events.Event event)
Get the command's short description.
|
String |
getDetails()
Get the command's detailed description.
|
String |
getDetails(net.dv8tion.jda.api.events.Event event)
Get the command's detailed description.
|
List<String> |
getExamples()
Get a list of example usages.
|
String |
getGroup()
get the command group's name or category.
|
String |
getGroup(net.dv8tion.jda.api.events.Event event)
get the command group's name or category.
|
List<net.dv8tion.jda.api.Permission> |
getMemberPermissions()
Get the list of Permission required by the Discord member in the server to execute this command.
|
String |
getName()
get the command's name.
|
String |
getName(net.dv8tion.jda.api.events.Event event)
get the command's name.
|
Throttling |
getThrottling()
Get the Throttling configuration for this command.
|
protected String |
hasPermission(net.dv8tion.jda.api.events.Event event)
Custom check of permission.
|
protected String |
hasPermission(net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
Custom check of permission
|
protected String |
hasPermission(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event)
Custom check of permission
|
boolean |
isGuildOnly()
Checks if the command should only be used inside a Discord server.
|
boolean |
isNsfw()
Checks if the command should only be used in channels marked as NSFW.
|
boolean |
isPrivateUseOnly()
Checks if the command should only be used in Direct Messages.
|
boolean |
isRunInThread()
Checks if the command should run inside a Discord Thread.
|
boolean |
isThreadOnly()
Checks if the command should only be used inside threads.
|
void |
onDirectMessageReceived(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
Handles a command call from Direct Messages.
|
void |
onGuildMessageReceived(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
Handles a command call from a Normal Server Channel.
|
void |
onGuildThreadMessageReceived(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
Handles a command call from a Thread Server Channel.
|
abstract void |
run(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event,
@NotNull Map<String,IArgument> args)
Command execution after all validations has been passed.
|
protected void |
sendReply(@NotNull net.dv8tion.jda.api.events.Event event,
@NotNull net.dv8tion.jda.api.EmbedBuilder reply)
Reply to the Original Message that executed this command.
|
protected void |
sendReply(@NotNull net.dv8tion.jda.api.events.Event event,
@NotNull net.dv8tion.jda.api.entities.MessageEmbed reply)
Reply to the Original Message that executed this command.
|
protected void |
sendReply(@NotNull net.dv8tion.jda.api.events.Event event,
@NotNull String reply)
Reply to the Original Message that executed this command.
|
protected void |
sendReply(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event,
@NotNull net.dv8tion.jda.api.EmbedBuilder reply)
Reply to the Original Message that executed this command.
|
protected void |
sendReply(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event,
@NotNull net.dv8tion.jda.api.entities.MessageEmbed reply)
Reply to the Original Message that executed this command.
|
void |
sendReply(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event,
@NotNull String reply)
Reply to the Original Message that executed this command.
|
protected void |
sendReply(@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event,
@NotNull net.dv8tion.jda.api.EmbedBuilder reply,
boolean ephemeral)
Reply to the Original Message that executed this command.
|
protected void |
sendReply(@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event,
@NotNull net.dv8tion.jda.api.entities.MessageEmbed reply,
boolean ephemeral)
Reply to the Original Message that executed this command.
|
protected void |
sendReply(@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event,
@NotNull String reply,
boolean ephemeral)
Reply to the Original Message that executed this command.
|
Command |
setDetails(String details)
Set a detailed description of this command
|
protected Command |
setGuildOnly()
Mark this command as Guild only.
|
protected Command |
setNotRunInThreads()
Mark this command as not compatible with Threads
The command will not be available to run inside Discord's threads
NOTE: this flag will remove Thread Only flag.
|
protected Command |
setNsfw()
Mark this command to only be usable in channels marked as NSFW.
|
protected Command |
setPrivateUseOnly()
Mark this command as Private Only
This command will not be able inside any Discord Server.
|
protected Command |
setThreadOnly()
Mark this command as Thread only
The command will not be available to run in a normal Text Channel
The command will not be available inside a Private Message.
|
protected Command |
setThrottling(Throttling throttling)
Set the throttling configuration for this command.
|
protected boolean |
shouldRun(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
Check if the command should be run in the current Message Channel.
|
String |
toString() |
String |
usage(String arg,
@NotNull net.dv8tion.jda.api.events.Event event)
Generates an example usage of the command.
|
public Command(@NotNull
@NotNull String name,
@NotNull
@NotNull String group,
String description,
IArgument... args)
throws DuplicatedArgumentNameException
You may implement Slash to include this command
as a Discord's Slash Command
name - Command name. It must be unique.group - Group's name. It is used by the default help command to categorize commands.
It has no real effects in the engine.description - Command's description, It is used by the default help command to explain what the command do.
It has no real effects in the engine.args - List of Arguments accepted by this command.DuplicatedArgumentNameException - Thrown when another Command with the same name has already been
registered in the Enginepublic abstract void run(@NotNull
@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event,
@NotNull
@NotNull Map<String,IArgument> args)
event - Discord event that triggered this command callargs - Already parsed arguments, Map's keys are the argument's namepublic Command setDetails(String details)
details - detailed descriptionprotected final Command addAliases(String... aliases)
aliases - list of aliases or alternative names.protected final Command addExample(String example)
example - usage example.protected final Command addExamples(String... example)
example - usage examples list.protected final Command addClientPermissions(net.dv8tion.jda.api.Permission... permissions)
i.e. SEND_MESSAGE in order to send a message to a Discord Channel.
permissions - Discord Permissions list.Permissionprotected final Command addMemberPermissions(net.dv8tion.jda.api.Permission... permissions)
i.e. ADMINISTRATOR in order to prevent normal users to modify the bot setting in this server.
permissions - Discord Permissions list.Permissionprotected final boolean shouldRun(@NotNull
@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
event - Discord Event that triggered this function call.@Nullable protected final @Nullable String checkClientPermissions(net.dv8tion.jda.api.events.Event event)
event - Discord Event that triggered this function call.Permission@Nullable protected final @Nullable String checkMemberPermissions(net.dv8tion.jda.api.events.Event event)
event - Discord Event that triggered this function call.Permissionprotected String hasPermission(net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
event - Message Event that triggered this function Callprotected String hasPermission(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event)
event - Slash Command Event that triggered this function Callprotected String hasPermission(net.dv8tion.jda.api.events.Event event)
event - Generic Event that triggered this function Callpublic final void sendReply(@NotNull
@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event,
@NotNull
@NotNull String reply)
If the command was called inside a Guild
event - Discord event that triggered this function callreply - reply messagePermission,
Guildprotected final void sendReply(@NotNull
@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event,
@NotNull
@NotNull net.dv8tion.jda.api.EmbedBuilder reply)
If the command was called inside a Guild
event - Discord event that triggered this function callreply - EmbedBuilder messagePermission,
Guild,
EmbedBuilderprotected final void sendReply(@NotNull
@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event,
@NotNull
@NotNull net.dv8tion.jda.api.entities.MessageEmbed reply)
If the command was called inside a Guild
event - Discord event that triggered this function callreply - MessageEmbedPermission,
Guild,
MessageEmbedprotected final void sendReply(@NotNull
@NotNull net.dv8tion.jda.api.events.Event event,
@NotNull
@NotNull String reply)
If the command was called inside a Guild
event - Discord event that triggered this function callreply - reply messagePermission,
Guildprotected final void sendReply(@NotNull
@NotNull net.dv8tion.jda.api.events.Event event,
@NotNull
@NotNull net.dv8tion.jda.api.EmbedBuilder reply)
If the command was called inside a Guild
event - Discord event that triggered this function callreply - EmbedBuilder messagePermission,
Guild,
EmbedBuilderprotected final void sendReply(@NotNull
@NotNull net.dv8tion.jda.api.events.Event event,
@NotNull
@NotNull net.dv8tion.jda.api.entities.MessageEmbed reply)
If the command was called inside a Guild
event - Discord event that triggered this function callreply - MessageEmbedPermission,
Guild,
MessageEmbedprotected final void sendReply(@NotNull
@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event,
@NotNull
@NotNull String reply,
boolean ephemeral)
If the command was called inside a Guild
event - Discord event that triggered this function callreply - reply messageephemeral - True, if this message should be invisible for other users.Permission,
Guildprotected final void sendReply(@NotNull
@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event,
@NotNull
@NotNull net.dv8tion.jda.api.EmbedBuilder reply,
boolean ephemeral)
If the command was called inside a Guild
event - Discord event that triggered this function callreply - EmbedBuilder messageephemeral - True, if this message should be invisible for other users.Permission,
Guild,
EmbedBuilderprotected final void sendReply(@NotNull
@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event,
@NotNull
@NotNull net.dv8tion.jda.api.entities.MessageEmbed reply,
boolean ephemeral)
If the command was called inside a Guild
event - Discord event that triggered this function callreply - MessageEmbedephemeral - True, if this message should be invisible for other users.Permission,
Guild,
MessageEmbedprotected Command setThrottling(Throttling throttling)
throttling - throttling configurationprotected Command setNsfw()
NOTE: If the command is called in a Private message, it will be treated as a NSFW channel.
protected Command setGuildOnly()
The command will not be available inside a Private message.
The command will not be listed by the default help command in a Private message, unless the argument all is included
protected Command setNotRunInThreads()
The command will not be available to run inside Discord's threads
NOTE: this flag will remove Thread Only flag.
protected Command setThreadOnly()
The command will not be available to run in a normal Text Channel
The command will not be available inside a Private Message.
NOTE: this flag will remove the Not Run in threads flag.
protected Command setPrivateUseOnly()
This command will not be able inside any Discord Server.
NOTE: this flag has priority over Guild only and Thread only tags.
public final void onDirectMessageReceived(@NotNull
@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
ICommandonDirectMessageReceived in interface ICommandevent - Discord event that triggered this function call.public final void onGuildThreadMessageReceived(@NotNull
@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
ICommandonGuildThreadMessageReceived in interface ICommandevent - Discord event that triggered this function call.public final void onGuildMessageReceived(@NotNull
@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
ICommandonGuildMessageReceived in interface ICommandevent - Discord event that triggered this function call.public String checkPermissions(net.dv8tion.jda.api.events.Event event)
ICommandcheckPermissions in interface ICommandevent - Discord event that triggered this function call.public String getGroup()
ICommandpublic String getDescription()
ICommandgetDescription in interface ICommandpublic String getName(net.dv8tion.jda.api.events.Event event)
ICommandpublic String getGroup(net.dv8tion.jda.api.events.Event event)
ICommandpublic String getDescription(net.dv8tion.jda.api.events.Event event)
ICommandgetDescription in interface ICommandevent - Discord's event that triggered this function call.public String getDetails(net.dv8tion.jda.api.events.Event event)
ICommandgetDetails in interface ICommandevent - Discord's event that triggered this function call.public List<IArgument> getArguments()
ICommandgetArguments in interface ICommandpublic List<String> getExamples()
ICommandgetExamples in interface ICommandpublic IArgument getArgument(String name)
ICommandgetArgument in interface ICommandname - Argument's name.public Throttling getThrottling()
ICommandgetThrottling in interface ICommandpublic boolean isNsfw()
ICommandpublic List<String> getAliases()
ICommandgetAliases in interface ICommandpublic List<net.dv8tion.jda.api.Permission> getClientPermissions()
ICommandgetClientPermissions in interface ICommandpublic List<net.dv8tion.jda.api.Permission> getMemberPermissions()
ICommandgetMemberPermissions in interface ICommandpublic boolean isGuildOnly()
ICommandisGuildOnly in interface ICommandpublic boolean isRunInThread()
ICommandisRunInThread in interface ICommandpublic boolean isThreadOnly()
ICommandisThreadOnly in interface ICommandpublic boolean isPrivateUseOnly()
ICommandisPrivateUseOnly in interface ICommandpublic String getDetails()
ICommandgetDetails in interface ICommand@NotNull public final @NotNull String anyUsage(net.dv8tion.jda.api.events.Event event)
ICommand