Zweih / JDA

Java Discord API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JDA (Java Discord API)

JDA strives to provide a clean and full wrapping of the Discord REST api and its Websocket-Events for Java.

JDA 2.x

After the release of the official Discord API, we decided to split JDA into 2 seperate libraries.

JDA will be continued with version 2.x and will only have Bot-features (for bot-accounts). Please see the Discord docs for more information about bot accounts.

We are also creating a new library called JDA-Client, which extends the functionality of JDA 2.x and add some client-only features like friends-list, acks, creating/owning Guilds,...
You can find JDA-Client Here

Creating the JDA Object

Creating the JDA Object is done via the JDABuilder class. After setting the bot-token via setter, the JDA Object is then created by calling the .buildBlocking() or the .buildAsync() (non-blocking login) method.

Example:

JDA jda = new JDABuilder().setBotToken("token").buildBlocking();

Events

There a TON of events in JDA that you can listen to.
There are 2 ways of writing your Event-Listener:

  1. Extend ListenerAdapter and use the provided methods that get fire dependent on the Event-Type. Event Methods
  2. Implement EventListener and listen to onEvent and figure out if it is the event you want (Not suggested)

Listeners can be registered either in the JDABuilder (will catch all Events; recommended), or in the JDA instance (initial Events, especially the READY-Event could get lost)

Examples:

public class ReadyListener implements EventListener
{
    public static void main(String[] args)
    {
        JDA jda = new JDABuilder().setBotToken("token").addListener(new ReadyListener()).buildBlocking();
    }

    @Override
    public void onEvent(Event event)
    {
        if(event instanceof ReadyEvent)
            System.out.println("API is ready!");
    }
}
public class MessageListener extends ListenerAdapter
{
    public static void main(String[] args)
    {
        JDA jda = new JDABuilder().setBotToken("token").buildBlocking();
        jda.addEventListener(new MessageListener());
    }

    @Override
    public void onMessageReceived(MessageReceivedEvent event)
    {
        if (event.isPrivate())
        {
            System.out.printf("[PM] %s: %s\n", event.getAuthor().getUsername(),
                                    event.getMessage().getContent());
        }
        else
        {
            System.out.printf("[%s][%s] %s: %s\n", event.getGuild().getName(),
                        event.getTextChannel().getName(), event.getAuthor().getUsername(),
                        event.getMessage().getContent());
        }
    }
}

More Examples

We provide a small set of Examples in the Example Directory.

Download

Current Promoted Version:

JDA promoted verison

You can get the latest promoted builds here: Promoted Downloads
(Contains information about Maven and Gradle distribution)

If you want the most up-to-date builds, you can get them here: Beta Build Downloads
Note: It is quite possible that these are broken or bugged. Use with caution.
The dev builds are also available for maven/gradle on JCenter through Bintray JDA JCenter Bintray

Docs

Javadocs are available in both jar format and web format.
The jar format is available on the Promoted Downloads page or on any of the build pages of the Beta Downloads.

The web format allows for viewing of the Latest Promoted Docs and also viewing of each individual build's javadoc. To view the javadoc for a specific build, you will need to go to that build's page on the build server and click the javadoc button on the left side of the build page.
A shortcut would be: http://home.dv8tion.net:8080/job/JDA/BUILD_NUMBER_GOES_HERE/javadoc/, you just need to replace the "BUILD_NUMBER_GOES_HERE" with the build you want.
Example: Build 90's javadoc url would be http://home.dv8tion.net:8080/job/JDA/90/javadoc/

Getting Help

If you need help, or just want to talk with the JDA or other Discord Devs, you can join the Unofficial Discord API Guild.

Once you joined, you can find JDA-specific help in the #java_jda channel

Contributing to JDA

If you want to contribute to JDA, make sure to base your branch off of our development branch (or a feature-branch) and create your PR into that same branch. We will be rejecting any PRs to master or between branches!

It is also highly recommended to get in touch with the Devs via the Discord API Guild (see section above).

Dependencies:

This project requires Java 8.
All dependencies are managed automatically by Gradle.

About

Java Discord API

License:Apache License 2.0


Languages

Language:Java 100.0%