Thanks for playing! Love, JDA and D4J devs.
The single best Discord API java wrapper
Download with maven
In order to create the DiscordAPI instance, you'll need to use the DiscordBuilder class.
Examples:
DiscordAPI api = new DiscordBuilder("email", "pass").build().login();
DiscordAPI api = new DiscordBuilder("email", "pass").build();
api.login();
In order to listen for an event, create a class that implements EventListener, and register it by calling api.getEventManager().registerListener(new YourListener(api));
. All events can be found in the discord.jar
package as well as the Events section.
public class ExampleListener implements EventListener {
DiscordAPI api;
public ExampleListener(DiscordAPI api){
this.api = api;
}
public void userChat(UserChatEvent e){
if (e.getMsg().getMessage().equals("#ping")){
e.getGroup().sendMessage(new MessageBuilder()
.addString("Yes, ")
.addUserTag(e.getGroupUser(), e.getGroup())
.addString("?")
.build());
}
System.out.println((e.getMsg().isEdited() ? "# " : "") + "[" + e.getGroup().getName() + "] " + e.getGroupUser() + " > " + e.getMsg().getMessage());
}
public void typing(UserTypingEvent e){
System.out.println(e.getGroupUser() + " is typing in " + e.getGroup());
}
}
public class Test {
public static void main(String[] args) {
DiscordAPI api = new DiscordAPI("email", "pass").login();
api.getEventManager().registerListener(new ExampleListener(api)); //Register listener
}
}
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
dependencies {
compile "com.github.discord-java:discord.jar:master-VERSION"
}