Skip to content

Latest commit

 

History

History
144 lines (118 loc) · 6.51 KB

README.md

File metadata and controls

144 lines (118 loc) · 6.51 KB

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 3.x

JDA will be continued with version 3.x and will support Bot-features (for bot-accounts) and Client-features (for user-accounts). Please see the Discord docs for more information about bot accounts.

This officially makes JDA-Client deprecated. Please do not continue using it, and instead switch to the promoted 3.x version listed further below.

Creating the JDA Object

Creating the JDA Object is done via the JDABuilder class by providing an AccountType (Bot/Client). After setting the 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(AccountType.BOT).setToken("token").buildBlocking();

Note: It is important to set the correct AccountType because Bot-accounts require a token prefix to login.

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(AccountType.BOT).setToken("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(AccountType.BOT).setToken("token").buildBlocking();
        jda.addEventListener(new MessageListener());
    }

    @Override
    public void onMessageReceived(MessageReceivedEvent event)
    {
        if (event.isFromType(ChannelType.PRIVATE))
        {
            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.getMember().getEffectiveName(),
                        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.