Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.
/ JDACommands Public archive

Light command framework for JDA Discord bots using annotations

License

Notifications You must be signed in to change notification settings

DevInfinityCOM/JDACommands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JDACommands

Light command framework for JDA Discord bots using annotations

How to use

Adding the dependency

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'
}

Creating a command

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:

  • Message
  • User
  • Member
  • Guild
  • JDA
  • String[] - the command arguments

Registering commands

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();
    }

About

Light command framework for JDA Discord bots using annotations

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages