Skip to main content
Used to create new JDA instances with custom configuration. A single JDABuilder can be reused multiple times to create multiple JDA instances with the same settings.

Creating a Builder

createDefault

Creates a JDABuilder with recommended default settings.
token
String
The bot token
intent
GatewayIntent
First intent to enable
intents
GatewayIntent...
Additional intents to enable
return
JDABuilder
Configured JDABuilder instance
Default Configuration:
  • Member cache policy: MemberCachePolicy.DEFAULT
  • Chunking filter: ChunkingFilter.NONE
  • Gateway intents: GatewayIntent.DEFAULT (if not specified)
  • Disabled cache: ACTIVITY, CLIENT_STATUS
JDABuilder builder = JDABuilder.createDefault(token);

// With specific intents
JDABuilder builder = JDABuilder.createDefault(
    token,
    GatewayIntent.GUILD_MESSAGES,
    GatewayIntent.MESSAGE_CONTENT
);

createLight

Creates a JDABuilder with low memory profile settings.
token
String
The bot token
intent
GatewayIntent
First intent to enable
intents
GatewayIntent...
Additional intents to enable
return
JDABuilder
Configured JDABuilder instance
Light Configuration:
  • Member cache policy: MemberCachePolicy.NONE
  • Chunking filter: ChunkingFilter.NONE
  • All cache flags disabled
  • Large threshold: 50
JDABuilder builder = JDABuilder.createLight(token);

create

Creates a completely empty JDABuilder with specified intents.
token
String
The bot token (can be set later)
intent
GatewayIntent
First intent to enable
intents
GatewayIntent... | Collection<GatewayIntent>
Additional intents to enable
return
JDABuilder
JDABuilder instance
// Create with specific intents
JDABuilder builder = JDABuilder.create(
    token,
    GatewayIntent.GUILD_MESSAGES,
    GatewayIntent.GUILD_MEMBERS
);

// Create with no intents, configure later
JDABuilder builder = JDABuilder.create(token, EnumSet.noneOf(GatewayIntent.class));

Building the Instance

build

Builds the JDA instance and starts the login process.
return
JDA
The JDA instance
JDA jda = JDABuilder.createDefault(token)
    .enableIntents(GatewayIntent.MESSAGE_CONTENT)
    .build();

Configuration

Token

setToken

Sets the bot token for authentication.
token
String
required
The bot token from Discord Developer Portal
return
JDABuilder
The builder for chaining
builder.setToken("your-bot-token");

Gateway Intents

enableIntents

Enables specific gateway intents.
intent
GatewayIntent
required
First intent to enable
intents
GatewayIntent... | Collection<GatewayIntent>
Additional intents to enable
return
JDABuilder
The builder for chaining
builder.enableIntents(
    GatewayIntent.MESSAGE_CONTENT,
    GatewayIntent.GUILD_MEMBERS
);

// Or with a collection
builder.enableIntents(EnumSet.of(
    GatewayIntent.GUILD_MESSAGES,
    GatewayIntent.DIRECT_MESSAGES
));

disableIntents

Disables specific gateway intents.
intent
GatewayIntent
required
First intent to disable
intents
GatewayIntent... | Collection<GatewayIntent>
Additional intents to disable
return
JDABuilder
The builder for chaining
builder.disableIntents(GatewayIntent.GUILD_PRESENCES);

setEnabledIntents

Sets the complete list of enabled intents, replacing any previous configuration.
intent
GatewayIntent
required
First intent to enable
intents
GatewayIntent... | Collection<GatewayIntent>
Additional intents to enable
return
JDABuilder
The builder for chaining
builder.setEnabledIntents(GatewayIntent.getIntents(GatewayIntent.ALL_INTENTS));

Cache Configuration

enableCache

Enables specific cache flags.
flag
CacheFlag
required
First cache flag to enable
flags
CacheFlag... | Collection<CacheFlag>
Additional cache flags to enable
return
JDABuilder
The builder for chaining
builder.enableCache(CacheFlag.ACTIVITY, CacheFlag.VOICE_STATE);

disableCache

Disables specific cache flags.
flag
CacheFlag
required
First cache flag to disable
flags
CacheFlag... | Collection<CacheFlag>
Additional cache flags to disable
return
JDABuilder
The builder for chaining
builder.disableCache(
    CacheFlag.ACTIVITY,
    CacheFlag.CLIENT_STATUS,
    CacheFlag.ONLINE_STATUS
);

setMemberCachePolicy

Configures which members to cache.
policy
MemberCachePolicy
required
The member cache policy
return
JDABuilder
The builder for chaining
// Cache only members in voice channels
builder.setMemberCachePolicy(MemberCachePolicy.VOICE);

// Cache voice members OR online members
builder.setMemberCachePolicy(
    MemberCachePolicy.VOICE.or(MemberCachePolicy.ONLINE)
);

// Don't cache any members
builder.setMemberCachePolicy(MemberCachePolicy.NONE);

setChunkingFilter

Configures which guilds should use member chunking.
filter
ChunkingFilter
required
The chunking filter
return
JDABuilder
The builder for chaining
// Don't chunk any guilds
builder.setChunkingFilter(ChunkingFilter.NONE);

// Chunk all guilds
builder.setChunkingFilter(ChunkingFilter.ALL);

// Chunk specific guilds only
builder.setChunkingFilter(ChunkingFilter.include(guildId1, guildId2));

Event Listeners

addEventListeners

Adds event listeners that will be registered when JDA is built.
listeners
Object...
required
One or more event listeners
return
JDABuilder
The builder for chaining
builder.addEventListeners(
    new MessageListener(),
    new ReadyListener()
);

setEventManager

Sets the event manager implementation.
manager
IEventManager
The event manager (null for default)
return
JDABuilder
The builder for chaining
// Use annotation-based events
builder.setEventManager(new AnnotatedEventManager());

Presence

setActivity

Sets the initial activity (game status) for the bot.
activity
Activity
The activity to display
return
JDABuilder
The builder for chaining
builder.setActivity(Activity.playing("with commands"));
builder.setActivity(Activity.listening("music"));
builder.setActivity(Activity.watching("the server"));
builder.setActivity(Activity.competing("a tournament"));

setStatus

Sets the initial online status for the bot.
status
OnlineStatus
required
The online status
return
JDABuilder
The builder for chaining
builder.setStatus(OnlineStatus.ONLINE);
builder.setStatus(OnlineStatus.IDLE);
builder.setStatus(OnlineStatus.DO_NOT_DISTURB);

setIdle

Sets whether the bot session should be marked as idle.
idle
boolean
required
Whether to mark as idle
return
JDABuilder
The builder for chaining
builder.setIdle(false);

Sharding

useSharding

Enables sharding mode for the bot.
shardId
int
required
The shard ID (0-based)
shardTotal
int
required
Total number of shards
return
JDABuilder
The builder for chaining
// Create shard 0 of 2 total shards
builder.useSharding(0, 2);

Thread Pools

setCallbackPool

Sets the executor for RestAction callbacks.
executor
ExecutorService
The executor service
automaticShutdown
boolean
default:"true"
Whether JDA should shutdown this pool
return
JDABuilder
The builder for chaining
ExecutorService executor = Executors.newFixedThreadPool(4);
builder.setCallbackPool(executor, true);

setGatewayPool

Sets the executor for gateway operations.
pool
ScheduledExecutorService
The scheduled executor service
automaticShutdown
boolean
default:"true"
Whether JDA should shutdown this pool
return
JDABuilder
The builder for chaining

setRateLimitPool

Sets the executor for rate limit handling.
pool
ScheduledExecutorService
The scheduled executor service
automaticShutdown
boolean
default:"true"
Whether JDA should shutdown this pool
return
JDABuilder
The builder for chaining

Behavior

setAutoReconnect

Configures automatic reconnection on connection errors.
autoReconnect
boolean
required
Whether to automatically reconnect
return
JDABuilder
The builder for chaining
builder.setAutoReconnect(true); // Default

setBulkDeleteSplittingEnabled

Configures whether bulk delete events should be split into individual events.
enabled
boolean
required
Whether to split bulk deletes
return
JDABuilder
The builder for chaining
builder.setBulkDeleteSplittingEnabled(false);

setEnableShutdownHook

Configures whether to use a shutdown hook for cleanup.
enable
boolean
required
Whether to enable shutdown hook
return
JDABuilder
The builder for chaining
builder.setEnableShutdownHook(true); // Default

setCompression

Sets the compression algorithm for the gateway connection.
compression
Compression
required
The compression type
return
JDABuilder
The builder for chaining
builder.setCompression(Compression.ZLIB); // Default
builder.setCompression(Compression.NONE); // Disable compression

HTTP Configuration

setHttpClient

Sets a custom OkHttpClient for REST requests.
client
OkHttpClient
The HTTP client
return
JDABuilder
The builder for chaining
OkHttpClient client = new OkHttpClient.Builder()
    .connectTimeout(30, TimeUnit.SECONDS)
    .build();
builder.setHttpClient(client);

setRestConfig

Sets custom REST configuration including rate limit handling.
config
RestConfig
required
The REST configuration
return
JDABuilder
The builder for chaining
RestConfig config = new RestConfig()
    .setBaseUrl("https://discord.com/api/v10")
    .setTimeout(20000);
builder.setRestConfig(config);

Complete Example

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.ChunkingFilter;
import net.dv8tion.jda.api.utils.MemberCachePolicy;
import net.dv8tion.jda.api.utils.cache.CacheFlag;

public class Bot {
    public static void main(String[] args) throws Exception {
        JDA jda = JDABuilder.createDefault("token")
            // Configure intents
            .enableIntents(
                GatewayIntent.MESSAGE_CONTENT,
                GatewayIntent.GUILD_MEMBERS
            )
            // Configure caching
            .setMemberCachePolicy(MemberCachePolicy.VOICE)
            .setChunkingFilter(ChunkingFilter.NONE)
            .disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS)
            // Set presence
            .setActivity(Activity.playing("with commands"))
            // Add listeners
            .addEventListeners(new MessageListener())
            // Build
            .build()
            .awaitReady();
        
        System.out.println("Bot is ready!");
    }
}

Build docs developers (and LLMs) love