This guide will walk you through the basics of creating a Discord bot using JM JDA Expansion, a tool developed by JM, to simplify bot coding with JDA (Java Discord API).
First, you need to create a new Java project in your favorite IDE (Integrated Development Environment) or text editor. Make sure you have JDA and JM JDA Expansion added as dependencies in your project.
You can add the JM JDA Expansion dependency to your pom.xml if you're using Maven:
<dependency>
<groupId>org.vitacraft</groupId>
<artifactId>jmjda</artifactId>
<version>1.0.0</version> <!-- Replace with the latest version -->
</dependency>Here's how you can create an empty bot using JM JDA Expansion:
public static void main(String[] args) {
JMBot bot = JMJDA.build("bot token here");
}Yes, it is really that simple! With JM-JDA creating your empty bot is not longer than one line!
Now, let's create a simple "ping" command. We'll guide you through the process step by step.
First, create a new Java class for your command. Let's name it PingCommand:
public class PingCommand implements PrimitiveCommand {
@Override
public String getName() {
return "ping";
}
@Override
public String getDescription() {
return "A simple Ping Pong command";
}
@Override
public Permission[] getNeededPermissions() {
return new Permission[0];
}
@Override
public Channel[] getPermittedChannels() {
return new Channel[0];
}
@Override
public void execute(MessageReceivedEvent event, String[] args) {
event.getMessage().reply("pong").queue();
}
@Override
public void missingPermissions(MessageReceivedEvent event, String[] args) {
event.getMessage().reply("You may not use this.").queue();
}
}Next, you need to register the command in your main bot class like so:
bot.getPrimitiveCommandsManager().registerCommand(new PingCommand());