A command manager made for JDA 4
- set the prefix
CommandHandler commandHandler = new CommandHandler(".");
jdabuilder.addEventListeners(commandHandler.getListener());
commandHandler.addCommands(new MsgCommand(), new SayCommand());
public class SayCommand extends Command {
}
public class MsgCommand extends AdvancedCommand {
}
-
public boolean cancel(String[] args, MessageReceivedEvent event){}
returns if the command will be excecuted. If true error will triggered
-
Command:
public void action(String[] args, MessageReceivedEvent event) throws Exception{}
-
AdvancedCommand:
public void action(Object[] args, MessageReceivedEvent event) throws Exception{}
execute the command
-
public void error(String[] args, MessageReceivedEvent event){}
:called if an exception was thrown, cancel returns true
-
public void setArguments(){}
-
public void setChannelTypes(){}
called on creating command. Can be used to set the command arguments and set the channel types which can trigger the command
- name = the function of the argument
- required = if you have to use this argument
- type = type of CommandArgument.ArgumentType
addArgument("user", true, CommandArgument.ArgumentType.USER_MENTION);
addArgument("text", true, CommandArgument.ArgumentType.STRING);
Type | Example | Object |
---|---|---|
WORD | set | string |
STRING | "any message" | string |
USER_MENTION | @username | string (user ID) |
CHANNEL_MENTION | #channelname | string (channel ID) |
ROLE_MENTION | @rolename | string (role ID) |
INTEGER | 10 | Integer |
BOOLEAN | true/1 | Boolean |
addChannelType(ChannelType.TEXT);