This tutorial provides a beginner-friendly click by click guide to set up Javacord with Eclipse and Maven. If you are already familiar with Eclipse and Maven, you can just see the artifact locations at [Download / Installation](/wiki/getting-started/download-installation.md). Eclipse + Maven
Info
We recommend to use Intellij + Gradle unless you already have experience with one of the other IDEs or build managers.
🔧 Setup
1. Start Eclipse
File
-> New
-> Project
)
2. Create a new project (Maven Project
3. Select Next
4. Click Create a simple project
5. Check Next
6. Click com.github.yourname
)
7. Enter a group id (e.g. myfirstbot
)
8. Enter an artifact id (e.g. Finish
9. Click pom.xml
file
10. Double click on the pom.xml
11. Select 12. Now you have to add Javacord as a dependency by editing the pom.xml file. Your file should now look like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>your.package.name</groupId>
<artifactId>myfirstbot</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.javacord</groupId>
<artifactId>javacord</artifactId>
<version>$latest-version</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
src/main/java
folder
13. Create a new package inside the 14. Create a new class inside this package
15. Save the project (you should do this from time to time)
16. Now you can start coding! Example code:
package com.github.yourname.myfirstbot;
import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
public class Main {
public static void main(String[] args) {
// Insert your bot's token here
String token = "your token";
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
// Add a listener which answers with "Pong!" if someone writes "!ping"
api.addMessageCreateListener(event -> {
if (event.getMessageContent().equalsIgnoreCase("!ping")) {
event.getChannel().sendMessage("Pong!");
}
});
// Print the invite url of your bot
System.out.println("You can invite the bot by using the following url: " + api.createBotInvite());
}
}
🏃♀️ Run the code
You can run your code by clicking on the small green arrow