version jenkins-shield license-shield discord-shield faq-shield troubleshooting-shield migration-shield

JDA (Java Discord API)

JDA strives to provide a clean and full wrapping of the Discord REST api and its Websocket-Events for Java. This library is a helpful tool that provides the functionality to create a discord bot in java.


Due to official statements made by the Discord developers we will no longer support unofficial features. These features are undocumented API endpoints or protocols that are not available to bot-accounts.

Please see the Discord docs for more information about bot accounts.

  1. Introduction
  2. Sharding
  3. Entity Lifetimes
  4. Download
  5. Documentation
  6. Support
  7. Extensions And Plugins
  8. Contributing
  9. Dependencies
  10. Other Libraries

UserBots and SelfBots

Discord is currently prohibiting creation and usage of automated client accounts (AccountType.CLIENT). We have officially dropped support for client login as of version 4.2.0! Note that JDA is not a good tool to build a custom discord client as it loads all servers/guilds on startup unlike a client which does this via lazy loading instead. If you need a bot, use a bot account from the Application Dashboard.

Read More

Creating the JDA Object

Creating the JDA Object is done via the JDABuilder class. After setting the token and other options via setters, the JDA Object is then created by calling the build() method. When build() returns, JDA might not have finished starting up. However, you can use awaitReady() on the JDA object to ensure that the entire cache is loaded before proceeding. Note that this method is blocking and will cause the thread to sleep until startup has completed.


JDA jda = JDABuilder.createDefault("token").build();


Both the JDABuilder and the DefaultShardManagerBuilder allow a set of configurations to improve the experience.


public static void main(String[] args) {
    JDABuilder builder = JDABuilder.createDefault(args[0]);

    // Disable parts of the cache
    builder.disableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE);
    // Enable the bulk delete event
    // Disable compression (not recommended)
    // Set activity (like "playing Something")

See JDABuilder and DefaultShardManagerBuilder

You can configure the memory usage by changing enabled CacheFlags on the JDABuilder. Additionally, you can change the handling of member/user cache by setting either a ChunkingFilter, disabling intents, or changing the member cache policy.

public void configureMemoryUsage(JDABuilder builder) {
    // Disable cache for member activities (streaming/games/spotify)

    // Only cache members who are either in a voice channel or owner of the guild

    // Disable member chunking on startup

    // Disable presence updates and typing events
    builder.disableIntents(GatewayIntent.GUILD_PRESENCE, GatewayIntent.GUILD_MESSAGE_TYPING);

    // Consider guilds with more than 50 members as "large". 
    // Large guilds will only provide online members in their setup and thus reduce bandwidth if chunking is disabled.

Listening to Events

The event system in JDA is configured through a hierarchy of classes/interfaces. We offer two implementations for the IEventManager:

By default the InterfacedEventManager is used. Since you can create your own implementation of IEventManager this is a very versatile and configurable system. If the aforementioned implementations don't suit your use-case you can simply create a custom implementation and configure it on the JDABuilder with setEventManager(...).


Using EventListener:

public class ReadyListener implements EventListener
    public static void main(String[] args)
            throws LoginException, InterruptedException
        // Note: It is important to register your ReadyListener before building
        JDA jda = JDABuilder.createDefault("token")
            .addEventListeners(new ReadyListener())

        // optionally block until JDA is ready

    public void onEvent(GenericEvent event)
        if (event instanceof ReadyEvent)
            System.out.println("API is ready!");

Using ListenerAdapter:

public class MessageListener extends ListenerAdapter
    public static void main(String[] args)
            throws LoginException
        JDA jda = JDABuilder.createDefault("token").build();
        //You can also add event listeners to the already built JDA instance
        // Note that some events may not be received if the listener is added after calling build()
        // This includes events such as the ReadyEvent
        jda.addEventListeners(new MessageListener());

    public void onMessageReceived(MessageReceivedEvent event)
        if (event.isFromType(ChannelType.PRIVATE))
            System.out.printf("[PM] %s: %s\n", event.getAuthor().getName(),
            System.out.printf("[%s][%s] %s: %s\n", event.getGuild().getName(),
                        event.getTextChannel().getName(), event.getMember().getEffectiveName(),

Ping-Pong Bot:

public class Bot extends ListenerAdapter
    public static void main(String[] args) throws LoginException
        if (args.length < 1) {
            System.out.println("You have to provide a token as first argument!");
        // args[0] should be the token
        // We only need 2 intents in this bot. We only respond to messages in guilds and private channels.
        // All other events will be disabled.
        JDABuilder.createLight(args[0], GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES)
            .addEventListeners(new Bot())
            .setActivity(Activity.playing("Type !ping"))

    public void onMessageReceived(MessageReceivedEvent event)
        Message msg = event.getMessage();
        if (msg.getContentRaw().equals("!ping"))
            MessageChannel channel = event.getChannel();
            long time = System.currentTimeMillis();
            channel.sendMessage("Pong!") /* => RestAction<Message> */
                   .queue(response /* => Message */ -> {
                       response.editMessageFormat("Pong: %d ms", System.currentTimeMillis() - time).queue();


Through RestAction we provide request handling with

and it is up to the user to decide which pattern to utilize. It can be combined with reactive libraries such as reactor-core due to being lazy.

The RestAction interface also supports a number of operators to avoid callback hell:


public RestAction<Void> selfDestruct(MessageChannel channel, String content) {
    return channel.sendMessage("The following message will destroy itself in 1 minute!")
        .delay(10, SECONDS, scheduler) // edit 10 seconds later
        .flatMap((it) -> it.editMessage(content))
        .delay(1, MINUTES, scheduler) // delete 1 minute later

More Examples

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

Sharding a Bot

Discord allows Bot-accounts to share load across sessions by limiting them to a fraction of the total connected Guilds/Servers of the bot.
This can be done using sharding which will limit JDA to only a certain amount of Guilds/Servers including events and entities. Sharding will limit the amount of Guilds/Channels/Users visible to the JDA session so it is recommended to have some kind of elevated management to access information of other shards.

To use sharding in JDA you will need to use JDABuilder.useSharding(int shardId, int shardTotal). The shardId is 0-based which means the first shard has the ID 0. The shardTotal is the total amount of shards (not 0-based) which can be seen similar to the length of an array, the last shard has the ID of shardTotal - 1.

The SessionController is a tool of the JDABuilder that allows to control state and behaviour between shards (sessions). When using multiple builders to build shards you have to create one instance of this controller and add the same instance to each builder: builder.setSessionController(controller)

Since version 3.4.0 JDA provides a ShardManager which automates this building process.

Example Sharding - Using JDABuilder

public static void main(String[] args) throws Exception
    JDABuilder shardBuilder = JDABuilder.createDefault(args[0]);
    //register your listeners here using shardBuilder.addEventListeners(...)
    shardBuilder.addEventListeners(new MessageListener());
    for (int i = 0; i < 10; i++)
        shardBuilder.useSharding(i, 10)

When the useSharding method is invoked for the first time, the builder automatically sets a SessionController internally (if none is present)

Example Sharding - Using DefaultShardManager

public static void main(String[] args) throws Exception
    DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.createDefault(args[0]);
    builder.addEventListeners(new MessageListener());;

Entity Lifetimes

An Entity is the term used to describe types such as GuildChannel/Message/User and other entities that Discord provides. Instances of these entities are created and deleted by JDA when Discord instructs it. This means the lifetime depends on signals provided by the Discord API which are used to create/update/delete entities. This is done through Gateway Events known as "dispatches" that are handled by the JDA WebSocket handlers. When Discord instructs JDA to delete entities, they are simply removed from the JDA cache and lose their references. Once that happens, nothing in JDA interacts or updates the instances of those entities, and they become useless. Discord may instruct to delete these entities randomly for cache synchronization with the API.

It is not recommended to store any of these entities for a longer period of time! Instead of keeping (e.g.) a User instance in some field, an ID should be used. With the ID of a user, you can use getUserById(id) to get and keep the user reference in a local variable (see below).

Fake Entities

Some entities in JDA are marked through an interface called IFakeable. These entities can exist outside of the JDA cache and are inaccessible through the common get...ById(id) methods. Fake entities are essentially instances that are not directly referenced by the JDA cache and are only temporarily created for a specific usage. It may be used for the author of a message that has left the guild when requesting the history of a MessageChannel or for Emote instances used in a Message that are not part of any of the guilds available to the bot.

Entity Updates

When an entity is updated through its manager, they will send a request to the Discord API which will update the state of the entity. The success of this request does not imply the entity has been updated yet. All entities are updated by the aforementioned Gateway Events which means you cannot rely on the cache being updated yet once the execution of a RestAction has completed. Some requests rely on the cache being updated to correctly update the entity. An example of this is updating roles of a member which overrides all roles of the member by sending a list of the new set of roles. This is done by first checking the current cache, the roles the member has right now, and appending or removing the requested roles. If the cache has not yet been updated by an event, this will result in unexpected behavior.

Entity Deletion

Discord may request that a client (the JDA session) invalidates its entire cache. When this happens, JDA will remove all of its current entities and reconnect the session. This is signaled through the ReconnectEvent. When entities are removed from the JDA cache, they lose access to the encapsulating entities. For instance, a channel loses access to its guild. Once that happens, they are unable to make any API requests through RestAction and instead throw an IllegalStateException. It is highly recommended to only keep references to entities by storing their id and using the respective get...ById(id) method when needed.


public class UserLogger extends ListenerAdapter 
    private final long userId;

    public UserLogger(User user)
        this.userId = user.getIdLong();

    public void onMessageReceived(MessageReceivedEvent event)
        User author = event.getAuthor();
        Message message = event.getMessage();
        if (author.getIdLong() == userId)
            // Print the message of the user
            System.out.println(author.getAsTag() + ": " + message.getContentDisplay());

    public void onGuildJoin(GuildJoinEvent event)
        JDA api = event.getJDA();
        User user = api.getUserById(userId); // Acquire a reference to the User instance through the id
        user.openPrivateChannel().queue((channel) ->
            // Send a private message to the user
            channel.sendMessageFormat("I have joined a new guild: **%s**", event.getGuild().getName()).queue();


Latest Stable Version: GitHub Release Latest Version: version

Be sure to replace the VERSION key below with the one of the versions shown above!



Maven without Audio



dependencies {
    compile 'net.dv8tion:JDA:VERSION'

repositories {

Gradle without Audio

dependencies {
    compile ('net.dv8tion:JDA:VERSION') {
        exclude module: 'opus-java'

The builds are distributed using JCenter through Bintray JDA JCenter Bintray

If you do not need any opus de-/encoding done by JDA (voice receive/send with PCM) you can exclude opus-java entirely. This can be done if you only send audio with an AudioSendHandler which only sends opus (isOpus() = true). (See lavaplayer)

If you want to use a custom opus library you can provide the absolute path to OpusLibrary.loadFrom(String) before using the audio api of JDA. This works without opus-java-natives as it only requires opus-java-api.
For this setup you should only exclude opus-java-natives as opus-java-api is a requirement for en-/decoding.

See opus-java

Logging Framework - SLF4J

JDA is using SLF4J to log its messages.

That means you should add some SLF4J implementation to your build path in addition to JDA. If no implementation is found, following message will be printed to the console on startup:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.

JDA currently provides a fallback Logger in case that no SLF4J implementation is present. We strongly recommend to use one though, as that can improve speed and allows you to customize the Logger as well as log to files

The most popular implementations are Log4j 2 and Logback


Docs can be found on the Jenkins or directly here
A simple Wiki can also be found in this repository's Wiki section


We use a number of annotations to indicate future plans for implemented functionality such as new features of the Discord API.


Getting Help

For general troubleshooting you can visit our wiki Troubleshooting-Troubleshooting) and FAQ-FAQ).
If you need help, or just want to talk with the JDA or other Devs, you can join the Official JDA Discord Guild.

Alternatively you can also join the Unofficial Discord API Guild. Once you joined, you can find JDA-specific help in the #java_jda channel.

For guides and setup help you can also take a look at the wiki
Especially interesting are the Getting Started-Getting-Started) and Setup-Setup) Pages.

Third Party Recommendations


Created and maintained by sedmelluq
LavaPlayer is the most popular library used by Music Bots created in Java. It is highly compatible with JDA and Discord4J and allows to play audio from Youtube, Soundcloud, Twitch, Bandcamp and more providers.
The library can easily be expanded to more services by implementing your own AudioSourceManager and registering it.

It is recommended to read the Usage section of LavaPlayer to understand a proper implementation.
Sedmelluq provided a demo in his repository which presents an example implementation for JDA:


Created and maintained by Frederik Mikkelsen, the creator of FredBoat.

Lavalink is a popular standalone audio sending node based on Lavaplayer. Lavalink was built with scalability in mind, and allows streaming music via many servers. It supports most of Lavaplayer's features.

Lavalink is used by many large bots, as well as bot developers who can not use a Java library like Lavaplayer. If you plan on serving music on a smaller scale with JDA it is often preferable to just use Lavaplayer directly as it is easier.

Lavalink-Client is the official Lavalink client for JDA.


Created and maintained by jagrosh.
JDA-Utilities provides a Command-Extension and several utilities to make using JDA very simple.

Features include:


Created and maintained by sedmelluq
Provides a native implementation for the JDA Audio Send-System to avoid GC pauses.

Note that this send system creates an extra UDP-Client which causes audio receive to no longer function properly since discord identifies the sending UDP-Client as the receiver.

JDABuilder builder = JDABuilder.createDefault(BOT_TOKEN)
    .setAudioSendFactory(new NativeAudioSendFactory());


Created and maintained by MinnDevelopment.
Provides Kotlin extensions for RestAction and events that provide a reactive alternative to common JDA interfaces.

fun main() {
    val manager = ReactiveEventManager()
           .subscribe { println("Ready to serve!") }
           .filter { it.message.contentRaw == "!ping" }
           .subscribe {"Pong!").queue() }

    val jda = JDABuilder.createDefault(BOT_TOKEN)

An example bot for this can be found at Reactive JDA Bot.

More can be found in our github organization: JDA-Applications

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 between branches or into release branches! It is very possible that your change might already be in development or you missed something.

More information can be found at the wiki page Contributing-Contributing)

Deprecation Policy

When a feature is introduced to replace or enhance existing functionality we might deprecate old functionality.

A deprecated method/class usually has a replacement mentioned in its documentation which should be switched to. Deprecated functionality might or might not exist in the next minor release. (Hint: The minor version is the MM of XX.MM.RR_BB in our version format)

It is possible that some features are deprecated without replacement, in this case the functionality is no longer supported by either the JDA structure due to fundamental changes (for example automation of a feature) or due to discord API changes that cause it to be removed.

We highly recommend to discontinue usage of deprecated functionality and update by going through each minor release instead of jumping. For instance, when updating from version 3.3.0 to version 3.5.1 you should do the following:

The BB indicates the build number specified in the release details.

The RR in version 3.4.RR should be replaced by the latest version that was published for 3.4, you can find out which the latest version was by looking at the release page


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

Related Projects

See also: