Class Command
- Direct Known Subclasses:
 AboutCommand,GuildlistCommand,PingCommand,RoleinfoCommand,ServerinfoCommand,ShutdownCommand,SlashCommand
Commands In JDA-Utilities
The internal inheritance for Commands used in JDA-Utilities is that of the Command object.
Classes created inheriting this class gain the unique traits of commands operated using the Commands Extension.
 
Using several fields, a command can define properties that make it unique and complex while maintaining
 a low level of development.
 
All Commands extending this class can define any number of these fields in a object constructor and then
 create the command action/response in the abstract
 #execute(CommandEvent) body:
 
 public class ExampleCmd extends Command {
      public ExampleCmd() {
          this.name = "example";
          this.aliases = new String[]{"test","demo"};
          this.help = "gives an example of commands do";
      }
      @Override
      protected void execute(CommandEvent) {
          event.reply("Hey look! This would be the bot's reply if this was a command!");
      }
 }
 Execution is with the provision of a MessageReceivedEvent-CommandClient wrapper called a
 CommandEvent and is performed in two steps:
 - Author:
 - John Grosh (jagrosh)
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classTo be used inCommands as a means of organizing commands into "Categories" as well as terminate command usage when the callingCommandEventdoesn't meet certain requirements. - 
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String[]The aliases of the command, when calling a command these function identically to calling theCommand.name.protected StringAn arguments format String for the command, used in the default help builder.protected Command.CategoryTheCategoryof the command.protected Command[]The child commands of the command.protected StringA small help String that summarizes the function of the command, used in the default help builder, and shown in the client for Slash Commands.protected BiConsumer<CommandEvent,Command> TheBiConsumerfor creating a help response to the format[prefix]<command name> help.protected booleantrueif this command should be hidden from the help.protected StringThe name of the command, allows the command to be called the formats:
Normal Command:[prefix]<command name>.protected StringA String name of a role required to use this command.protected booleantrueif this command checks a channel topic for topic-tags.Fields inherited from class com.jagrosh.jdautilities.command.Interaction
botMissingPermMessage, botPermissions, cooldown, cooldownScope, guildOnly, nsfwOnly, ownerCommand, userMissingPermMessage, userPermissions - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidexecute(CommandEvent event) The main body method of aCommand.String[]Gets theCommand.aliasesfor the Command.Gets theCommand.argumentsfor the Command.Gets theCommand.categoryfor the Command.Command[]Gets theCommand.childrenfor the Command.getCooldownError(CommandEvent event, int remaining) Gets an error message for this Command under the providedCommanEvent.getCooldownKey(CommandEvent event) Gets the proper cooldown key for this Command under the providedCommandEvent.getHelp()Gets theCommand.helpfor the Command.getName()Gets theCommand.namefor the Command.Gets theCommand.requiredRolefor the Command.booleanisAllowed(net.dv8tion.jda.api.entities.channel.concrete.TextChannel channel) Checks whether a command is allowed in aTextChannelby searching the channel topic for topic tags relating to the command.booleanisCommandFor(String input) Checks if the given input represents this CommandbooleanChecks if this Command can only be used in aGuild.booleanisHidden()Checks whether or not this command should be hidden from the help.final voidrun(CommandEvent event) Runs checks for theCommandwith the givenCommandEventthat called it.Methods inherited from class com.jagrosh.jdautilities.command.Interaction
getBotPermissions, getCooldown, getCooldownScope, getUserPermissions, isOwnerCommand 
- 
Field Details
- 
name
The name of the command, allows the command to be called the formats:
Normal Command:[prefix]<command name>.
Slash Command:/<command name> - 
help
A small help String that summarizes the function of the command, used in the default help builder, and shown in the client for Slash Commands. - 
category
TheCategoryof the command.
This can perform any other checks not completed by the default conditional fields. - 
arguments
An arguments format String for the command, used in the default help builder. Not supported for SlashCommands.- See Also:
 
 - 
requiredRole
A String name of a role required to use this command. - 
aliases
The aliases of the command, when calling a command these function identically to calling theCommand.name. This options only works for normal commands, not slash commands. - 
children
The child commands of the command. These are used in the format[prefix]<parent name> <child name>. - 
helpBiConsumer
TheBiConsumerfor creating a help response to the format[prefix]<command name> help. - 
usesTopicTags
protected boolean usesTopicTagstrueif this command checks a channel topic for topic-tags.
This means that putting{-commandname},{-command category},{-all}in a channel topic will cause this command to terminate.
Defaulttrue. 
 - 
 - 
Constructor Details
- 
Command
public Command() 
 - 
 - 
Method Details
- 
execute
- Parameters:
 event- TheCommandEventthat triggered this Command
 - 
run
Runs checks for theCommandwith the givenCommandEventthat called it.
Will terminate, and possibly respond with a failure message, if any checks fail.- Parameters:
 event- The CommandEvent that triggered this Command
 - 
isCommandFor
Checks if the given input represents this Command- Parameters:
 input- The input to check- Returns:
 trueif the input is the name or an alias of the Command
 - 
isAllowed
public boolean isAllowed(net.dv8tion.jda.api.entities.channel.concrete.TextChannel channel) Checks whether a command is allowed in aTextChannelby searching the channel topic for topic tags relating to the command.{-
name}, {-category name}, or {-all} are valid examples of ways that this method would returnfalseif placed in a channel topic.NOTE:Topic tags are case sensitive and proper usage must be in lower case!
Also note that settingusesTopicTagstofalsewill cause this method to always returntrue, as the feature would not be applicable in the first place.- Parameters:
 channel- The TextChannel to test.- Returns:
 trueif the channel topic doesn't specify any topic-tags that would cause this command to be cancelled, or ifusesTopicTagshas been set tofalse.
 - 
getName
Gets theCommand.namefor the Command.- Returns:
 - The name for the Command
 
 - 
getHelp
Gets theCommand.helpfor the Command.- Returns:
 - The help for the Command
 
 - 
getCategory
Gets theCommand.categoryfor the Command.- Returns:
 - The category for the Command
 
 - 
getArguments
Gets theCommand.argumentsfor the Command.- Returns:
 - The arguments for the Command
 
 - 
isGuildOnly
public boolean isGuildOnly()Checks if this Command can only be used in aGuild.- Returns:
 trueif this Command can only be used in a Guild, elsefalseif it can be used outside of one
 - 
getRequiredRole
Gets theCommand.requiredRolefor the Command.- Returns:
 - The requiredRole for the Command
 
 - 
getAliases
Gets theCommand.aliasesfor the Command.- Returns:
 - The aliases for the Command
 
 - 
getChildren
Gets theCommand.childrenfor the Command.- Returns:
 - The children for the Command
 
 - 
isHidden
public boolean isHidden()Checks whether or not this command should be hidden from the help.- Returns:
 trueif the command should be hidden, otherwisefalse
 - 
getCooldownKey
Gets the proper cooldown key for this Command under the providedCommandEvent.- Parameters:
 event- The CommandEvent to generate the cooldown for.- Returns:
 - A String key to use when applying a cooldown.
 
 - 
getCooldownError
Gets an error message for this Command under the providedCommanEvent.- Parameters:
 event- The CommandEvent to generate the error message for.remaining- The remaining number of seconds a command is on cooldown for.- Returns:
 - A String error message for this command if 
remaining > 0, elsenull. 
 
 -