Overview
The JDA interface is the main entry point for all Discord bot operations. It provides access to:- User and guild caches
- Event management
- REST operations
- WebSocket connection management
- Audio system
Creating a JDA Instance
Use JDABuilder to create a JDA instance:Connection Status
getStatus
Gets the current connection status of the JDA instance.The current JDA status
INITIALIZING- JDA is setting up supporting systemsINITIALIZED- Ready to log inLOGGING_IN- Currently attempting to log inCONNECTING_TO_WEBSOCKET- Connecting to Discord’s WebSocketIDENTIFYING_SESSION- Sending authenticationAWAITING_LOGIN_CONFIRMATION- Waiting for confirmationLOADING_SUBSYSTEMS- Populating internal objectsCONNECTED- Fully connected and operationalDISCONNECTED- WebSocket disconnectedRECONNECT_QUEUED- Waiting to reconnectATTEMPTING_TO_RECONNECT- Trying to reconnectSHUTTING_DOWN- Shutting downSHUTDOWN- Fully shut downFAILED_TO_LOGIN- Invalid authentication
awaitReady
Blocks the current thread until JDA reaches theCONNECTED status.
The current JDA instance for chaining
awaitStatus
Blocks until JDA reaches a specific status.The status to wait for
Optional failure states that force premature return
The current JDA instance for chaining
Gateway and Intents
getGatewayIntents
Returns the enabled gateway intents for this session.Set of active gateway intents
getCacheFlags
Returns the enabled cache flags for this session.Copy of the EnumSet of cache flags
Ping and Latency
getGatewayPing
The time in milliseconds that Discord took to respond to the last heartbeat.Time in milliseconds between heartbeat and acknowledgment
getRestPing
Requests the current user from the API and calculates response time.RestAction returning the REST ping in milliseconds
User Management
getSelfUser
Returns the currently logged in account.The bot’s user account
getUserById
Retrieves a cached user by ID.The user’s ID
The user, or null if not cached
retrieveUserById
Fetches a user from the API by ID. If cached, returns immediately.The user’s ID
RestAction that retrieves the user
getUserCache
Returns the cache view of all cached users.Cache view of users
Guild Management
getGuildById
Retrieves a cached guild by ID.The guild’s ID
The guild, or null if not cached
getGuilds
Returns an immutable list of all cached guilds.List of all guilds this bot is connected to
getGuildCache
Returns the cache view of all cached guilds.Cache view of guilds
Event Management
addEventListener
Adds event listeners to handle Discord events.One or more EventListener instances
removeEventListener
Removes previously registered event listeners.One or more EventListener instances to remove
setEventManager
Changes the internal event manager implementation.The new event manager (null to use default)
listenOnce
Creates a builder for one-time event listeners.The type of event to listen for
Builder for configuring the one-time listener
Command Management
retrieveCommands
Retrieves the list of global slash commands.Whether to include localization data
RestAction returning list of commands
upsertCommand
Creates or updates a global command.The command data
RestAction that creates or updates the command
updateCommands
Replaces all global commands with a new list.Action to configure and execute the update
deleteCommandById
Deletes a global command by ID.The command’s ID
RestAction to delete the command
Private Channels
openPrivateChannelById
Opens a private channel with a user.The user’s ID
RestAction that opens the private channel
Presence and Activity
getPresence
Returns the presence manager for this bot.The presence manager
Shutdown
shutdown
Gracefully shuts down JDA, finishing all pending requests.shutdownNow
Immediately shuts down JDA, cancelling all pending requests.awaitShutdown
Blocks until shutdown is complete.Maximum time to wait (0 = indefinite)
Time unit for duration
True if shutdown completed, false if timeout elapsed
Thread Pools
getRateLimitPool
Returns the executor used for rate-limit handling.The rate limit pool
getGatewayPool
Returns the executor used for WebSocket operations.The gateway pool
getCallbackPool
Returns the executor used for RestAction callbacks.The callback pool
Sharding
getShardInfo
Returns shard information for this instance.The shard info, or ShardInfo.SINGLE if not sharded
Related
- JDABuilder - Build and configure JDA instances
- RestAction - Asynchronous request handling