-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started
Badbird5907 edited this page Jun 5, 2022
·
8 revisions
<dependency>
<groupId>net.badbird5907</groupId>
<artifactId>JDACommand</artifactId>
<version>4.0.1-REL</version>
</dependency>
dependencies{
implementation 'net.badbird5907:JDACommand:4.0.1-REL'
}
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'
}
- Download the jar at https://github.com/Badbird5907/JDACommand/releases/
- Add the jar to your classpath
This is a quick example bot that says "Hello World" when you use "/hello":
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() + "!");
}
}
public class YourClass {
public static void main(String[] args) {
JDA jda = JDABuilder.createDefault("token").build();
JDACommand command = new JDACommand(jda);
command.registerCommand(new ExampleCommand());
}
}