Light command framework for JDA Discord bots using annotations
Maven
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories><dependencies>
<dependency>
<groupId>com.dev-infinity</groupId>
<artifactId>JDACommands</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>Gradle
repositories {
maven { url 'https://jitpack.io' }
}dependencies {
implementation 'com.dev-infinity:JDACommands:1.0.1'
}Create a method and add the annotation @CommandName, you can also add the annotation @CommandAlias to add alias
@CommandName("test")
@CommandAlias({"testcommand", "commandtest"})
public void testCommand(TextChannel channel) {
channel.sendMessage("Test command is working").queue();
}If you want to have one command per class you can add the annotations to the class and annotate the method with @CommandExecutor
@CommandName("test")
@CommandAlias({"testcommand", "commandtest"})
public class TestCommand {
@CommandExecutor
public void testCommand(TextChannel channel) {
channel.sendMessage("Test command is working").queue();
}
}Arguments can be one of the following types:
MessageUserMemberGuildJDAString[]- the command arguments
Just create a CommandManager instance and call executeCommand when the bot receive a message that can be a command
CommandManager commandManager = new CommandManager("!"); // '!' is the prefix for the commands
commandManager.register(new TestCommand());
try {
new JDABuilder("token").addEventListener(new ListenerAdapter() {
@Override
public void onMessageReceived(MessageReceivedEvent event) {
// Don't execute commands from bots
if (event.getAuthor().isBot()) {
return;
}
commandManager.executeCommand(event.getMessage());
}
}).build();
} catch (LoginException e) {
e.printStackTrace();
}