Skip to content

Getting Started

Badbird5907 edited this page Jun 5, 2022 · 8 revisions

Getting Started:

Add The Dependency:

Maven:

<dependency>
    <groupId>net.badbird5907</groupId>
    <artifactId>JDACommand</artifactId>
    <version>4.0.1-REL</version>
</dependency>

Gradle:

dependencies{
    implementation 'net.badbird5907:JDACommand:4.0.1-REL'
}

Important

To allow command argument names to work correctly, you need to pass -parameters to your compiler
Maven:

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven-compiler-plugin.version}</version>
        <configuration>
            <parameters>true</parameters>
        </configuration>
    </plugin>
</plugins>

Gradle:

compileJava {
    options.compilerArgs << '-parameters'
}

Classpath/jar

  1. Download the jar at https://github.com/Badbird5907/JDACommand/releases/
  2. Add the jar to your classpath

Writing The Application

This is a quick example bot that says "Hello World" when you use "/hello":

Usage:

Recommended usage:

public class YourClass {
    public static void main(String[] args) {
        JDA jda = JDABuilder.createDefault("token").build();
        JDACommand command = new JDACommand(jda);
        command.registerCommandsInPackage("your.package.commands");
    }
}

//in package your.package.commands
public class ExampleCommand {
    @Command(name = "hello", description = "Replies with \"Hello!\"")
    public void hello(CommandContext ctx, @Sender User sender) {
        ctx.reply("Hello, " + sender.getAsTag() + "!");
    }
}

Manually registering commands

public class YourClass {
    public static void main(String[] args) {
        JDA jda = JDABuilder.createDefault("token").build();
        JDACommand command = new JDACommand(jda);
        command.registerCommand(new ExampleCommand());
    }
}