CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-net-dv8tion--jda

Java Discord API - A comprehensive Java library for building Discord bots and applications

Pending
Overview
Eval results
Files

core-management.mddocs/

Core JDA Management

Core JDA management functionality for creating, configuring, and managing JDA instances and bot lifecycle operations.

Capabilities

JDA Interface

The main JDA interface serves as the central registry for all Discord API access and bot functionality.

/**
 * The core of JDA. Acts as a registry system of JDA. All parts of the API can be accessed starting from this class.
 */
interface JDA extends IGuildChannelContainer<Channel> {
    /** Get the current connection status */
    Status getStatus();
    
    /** Get the configured gateway intents */
    EnumSet<GatewayIntent> getGatewayIntents();
    
    /** Get the configured cache flags */
    EnumSet<CacheFlag> getCacheFlags();
    
    /** Get WebSocket ping latency in milliseconds */
    long getGatewayPing();
    
    /** Get REST API ping latency */
    RestPing getRestPing();
    
    /** Block until JDA is ready */
    JDA awaitReady() throws InterruptedException;
    
    /** Block until JDA reaches specific status */
    JDA awaitStatus(Status... status) throws InterruptedException;
    
    /** Gracefully shutdown JDA */
    void shutdown();
    
    /** Immediately shutdown JDA */
    void shutdownNow();
    
    /** Add event listeners */
    void addEventListener(Object... listeners);
    
    /** Remove event listeners */
    void removeEventListener(Object... listeners);
    
    /** Get cached users */
    SnowflakeCacheView<User> getUserCache();
    
    /** Get cached guilds */
    SnowflakeCacheView<Guild> getGuildCache();
    
    /** Retrieve user by ID */
    RestAction<User> retrieveUserById(long userId);
    RestAction<User> retrieveUserById(String userId);
    
    /** Get bot application info */
    RestAction<ApplicationInfo> retrieveApplicationInfo();
    
    /** Get bot's user account */
    SelfUser getSelfUser();
    
    /** Get shard information */
    ShardInfo getShardInfo();
    
    /** Get presence manager */
    Presence getPresence();
    
    /** Get event manager */
    IEventManager getEventManager();
    
    /** Get HTTP client */
    OkHttpClient getHttpClient();
    
    /** Get direct audio controller for voice connections */
    DirectAudioController getDirectAudioController();
}

Usage Examples:

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;

// Create and start bot
JDA jda = JDABuilder.createDefault("BOT_TOKEN").build();

// Wait for bot to be ready
jda.awaitReady();

// Check connection status
if (jda.getStatus() == JDA.Status.CONNECTED) {
    System.out.println("Bot is connected!");
}

// Get bot information
System.out.println("Bot name: " + jda.getSelfUser().getName());
System.out.println("Guild count: " + jda.getGuildCache().size());
System.out.println("Gateway ping: " + jda.getGatewayPing() + "ms");

// Shutdown gracefully
jda.shutdown();

JDABuilder

Builder pattern class for creating and configuring JDA instances with fluent API.

/**
 * Used to create new JDA instances. This is also useful for making sure all of
 * your EventListeners are registered before JDA attempts to log in.
 */
class JDABuilder {
    /** Create JDABuilder with recommended default settings */
    static JDABuilder createDefault(String token);
    
    /** Create JDABuilder with minimal cache settings */
    static JDABuilder createLight(String token);
    
    /** Create JDABuilder with all cache enabled */
    static JDABuilder create(String token);
    
    /** Set bot token */
    JDABuilder setToken(String token);
    
    /** Enable specific gateway intents */
    JDABuilder enableIntents(GatewayIntent... intents);
    JDABuilder enableIntents(Collection<GatewayIntent> intents);
    
    /** Disable specific gateway intents */
    JDABuilder disableIntents(GatewayIntent... intents);
    JDABuilder disableIntents(Collection<GatewayIntent> intents);
    
    /** Set all enabled intents */
    JDABuilder setEnabledIntents(Collection<GatewayIntent> intents);
    
    /** Enable cache flags */
    JDABuilder enableCache(CacheFlag... flags);
    JDABuilder enableCache(Collection<CacheFlag> flags);
    
    /** Disable cache flags */
    JDABuilder disableCache(CacheFlag... flags);
    JDABuilder disableCache(Collection<CacheFlag> flags);
    
    /** Set member cache policy */
    JDABuilder setMemberCachePolicy(MemberCachePolicy policy);
    
    /** Set chunking filter */
    JDABuilder setChunkingFilter(ChunkingFilter filter);
    
    /** Set event manager */
    JDABuilder setEventManager(IEventManager manager);
    
    /** Add event listeners */
    JDABuilder addEventListeners(Object... listeners);
    
    /** Set initial online status */
    JDABuilder setStatus(OnlineStatus status);
    
    /** Set initial activity */
    JDABuilder setActivity(Activity activity);
    
    /** Set whether to idle on startup */
    JDABuilder setIdle(boolean idle);
    
    /** Set HTTP client builder */
    JDABuilder setHttpClientBuilder(OkHttpClient.Builder builder);
    
    /** Set HTTP client */
    JDABuilder setHttpClient(OkHttpClient client);
    
    /** Set WebSocket factory */
    JDABuilder setWebsocketFactory(WebSocketFactory factory);
    
    /** Set rate limit scheduler */
    JDABuilder setRateLimitScheduler(ScheduledExecutorService scheduler);
    
    /** Set callback thread pool */
    JDABuilder setCallbackPool(ExecutorService executor);
    
    /** Set event thread pool */
    JDABuilder setEventPool(ExecutorService executor);
    
    /** Set audio thread pool */
    JDABuilder setAudioPool(ScheduledExecutorService executor);
    
    /** Set shard information for sharded bots */
    JDABuilder useSharding(int shardId, int shardTotal);
    
    /** Set session controller for shard coordination */
    JDABuilder setSessionController(SessionController controller);
    
    /** Set voice dispatch interceptor */
    JDABuilder setVoiceDispatchInterceptor(VoiceDispatchInterceptor interceptor);
    
    /** Set audio send factory */
    JDABuilder setAudioSendFactory(IAudioSendFactory factory);
    
    /** Set maximum reconnect delay */
    JDABuilder setMaxReconnectDelay(int maxReconnectDelay);
    
    /** Set large guild threshold */
    JDABuilder setLargeThreshold(int threshold);
    
    /** Set maximum buffer size */
    JDABuilder setMaxBufferSize(int bufferSize);
    
    /** Set compression type */
    JDABuilder setCompression(Compression compression);
    
    /** Set gateway encoding */
    JDABuilder setEncoding(GatewayEncoding encoding);
    
    /** Enable/disable specific config flags */
    JDABuilder setFlag(ConfigFlag flag, boolean enable);
    
    /** Set context map for request context */
    JDABuilder setContextMap(ConcurrentMap<String, String> map);
    
    /** Build and create JDA instance */
    JDA build() throws LoginException, InterruptedException;
}

Usage Examples:

import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.requests.GatewayIntent;
import java.util.EnumSet;

// Basic bot setup
JDA jda = JDABuilder.createDefault("BOT_TOKEN")
    .addEventListeners(new MyEventListener())
    .build();

// Message logging bot
JDA messageBot = JDABuilder.createLight("BOT_TOKEN", 
        EnumSet.of(GatewayIntent.GUILD_MESSAGES, GatewayIntent.MESSAGE_CONTENT))
    .addEventListeners(new MessageLogger())
    .setStatus(OnlineStatus.ONLINE)
    .setActivity(Activity.watching("for messages"))
    .build();

// Slash command bot (no special intents needed)
JDA slashBot = JDABuilder.createLight("BOT_TOKEN", Collections.emptyList())
    .addEventListeners(new SlashCommandHandler())
    .setStatus(OnlineStatus.ONLINE)
    .build();

// Advanced configuration
JDA advancedBot = JDABuilder.createDefault("BOT_TOKEN")
    .enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES)
    .setMemberCachePolicy(MemberCachePolicy.VOICE.or(MemberCachePolicy.OWNER))
    .setChunkingFilter(ChunkingFilter.NONE)
    .disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS)
    .setLargeThreshold(50)
    .addEventListeners(new MyEventListener())
    .build();

Connection Status

Enumeration representing the various states of the JDA connection lifecycle.

/**
 * Represents the connection status of JDA and its Main WebSocket.
 */
enum Status {
    /** JDA is currently setting up supporting systems like the AudioSystem */
    INITIALIZING(true),
    
    /** JDA has finished setting up supporting systems and is ready to log in */
    INITIALIZED(true),
    
    /** JDA is currently attempting to log in */
    LOGGING_IN(true),
    
    /** JDA is currently attempting to connect its websocket to Discord */
    CONNECTING_TO_WEBSOCKET(true),
    
    /** JDA has successfully connected its websocket to Discord and is sending authentication */
    IDENTIFYING_SESSION(true),
    
    /** JDA has sent authentication to discord and is awaiting confirmation */
    AWAITING_LOGIN_CONFIRMATION(true),
    
    /** JDA is populating internal objects */
    LOADING_SUBSYSTEMS(true),
    
    /** JDA has finished loading everything and is firing events */
    CONNECTED(true),
    
    /** JDA is ready to receive events and dispatch them to listeners */
    READY(true),
    
    /** JDA WebSocket connection was closed and a reconnect is being attempted */
    DISCONNECTED(false),
    
    /** JDA session has been added to SessionController queue for reconnect */
    RECONNECTING(false),
    
    /** JDA is currently shutting down */
    SHUTTING_DOWN(false),
    
    /** JDA has finished shutting down and cannot be used anymore */
    SHUTDOWN(false),
    
    /** An error occurred during login */
    FAILED_TO_LOGIN(false);
    
    /** Whether this status indicates the session is connected to Discord */
    boolean isConnected();
}

Shard Information

Information about the current shard for multi-shard deployments.

/**
 * Represents shard information for sharded JDA instances.
 */
class ShardInfo {
    /** Get shard ID (0-based) */
    int getShardId();
    
    /** Get total number of shards */
    int getShardTotal();
    
    /** Get shard string representation (id/total) */
    String getShardString();
}

Bot User Information

Information about the bot's own user account.

/**
 * Represents the bot's own user account with additional bot-specific information.
 */
interface SelfUser extends User {
    /** Get bot application ID */
    long getApplicationIdLong();
    String getApplicationId();
    
    /** Check if bot is verified */
    boolean isVerified();
    
    /** Check if bot can be added by users */
    boolean isMfaEnabled();
}

Install with Tessl CLI

npx tessl i tessl/maven-net-dv8tion--jda

docs

audio.md

core-management.md

entities.md

events.md

index.md

interactions.md

messaging.md

restactions.md

sharding.md

tile.json