or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

audio.mdcore-management.mdentities.mdevents.mdindex.mdinteractions.mdmessaging.mdrestactions.mdsharding.md

core-management.mddocs/

0

# Core JDA Management

1

2

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

3

4

## Capabilities

5

6

### JDA Interface

7

8

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

9

10

```java { .api }

11

/**

12

* The core of JDA. Acts as a registry system of JDA. All parts of the API can be accessed starting from this class.

13

*/

14

interface JDA extends IGuildChannelContainer<Channel> {

15

/** Get the current connection status */

16

Status getStatus();

17

18

/** Get the configured gateway intents */

19

EnumSet<GatewayIntent> getGatewayIntents();

20

21

/** Get the configured cache flags */

22

EnumSet<CacheFlag> getCacheFlags();

23

24

/** Get WebSocket ping latency in milliseconds */

25

long getGatewayPing();

26

27

/** Get REST API ping latency */

28

RestPing getRestPing();

29

30

/** Block until JDA is ready */

31

JDA awaitReady() throws InterruptedException;

32

33

/** Block until JDA reaches specific status */

34

JDA awaitStatus(Status... status) throws InterruptedException;

35

36

/** Gracefully shutdown JDA */

37

void shutdown();

38

39

/** Immediately shutdown JDA */

40

void shutdownNow();

41

42

/** Add event listeners */

43

void addEventListener(Object... listeners);

44

45

/** Remove event listeners */

46

void removeEventListener(Object... listeners);

47

48

/** Get cached users */

49

SnowflakeCacheView<User> getUserCache();

50

51

/** Get cached guilds */

52

SnowflakeCacheView<Guild> getGuildCache();

53

54

/** Retrieve user by ID */

55

RestAction<User> retrieveUserById(long userId);

56

RestAction<User> retrieveUserById(String userId);

57

58

/** Get bot application info */

59

RestAction<ApplicationInfo> retrieveApplicationInfo();

60

61

/** Get bot's user account */

62

SelfUser getSelfUser();

63

64

/** Get shard information */

65

ShardInfo getShardInfo();

66

67

/** Get presence manager */

68

Presence getPresence();

69

70

/** Get event manager */

71

IEventManager getEventManager();

72

73

/** Get HTTP client */

74

OkHttpClient getHttpClient();

75

76

/** Get direct audio controller for voice connections */

77

DirectAudioController getDirectAudioController();

78

}

79

```

80

81

**Usage Examples:**

82

83

```java

84

import net.dv8tion.jda.api.JDA;

85

import net.dv8tion.jda.api.JDABuilder;

86

87

// Create and start bot

88

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

89

90

// Wait for bot to be ready

91

jda.awaitReady();

92

93

// Check connection status

94

if (jda.getStatus() == JDA.Status.CONNECTED) {

95

System.out.println("Bot is connected!");

96

}

97

98

// Get bot information

99

System.out.println("Bot name: " + jda.getSelfUser().getName());

100

System.out.println("Guild count: " + jda.getGuildCache().size());

101

System.out.println("Gateway ping: " + jda.getGatewayPing() + "ms");

102

103

// Shutdown gracefully

104

jda.shutdown();

105

```

106

107

### JDABuilder

108

109

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

110

111

```java { .api }

112

/**

113

* Used to create new JDA instances. This is also useful for making sure all of

114

* your EventListeners are registered before JDA attempts to log in.

115

*/

116

class JDABuilder {

117

/** Create JDABuilder with recommended default settings */

118

static JDABuilder createDefault(String token);

119

120

/** Create JDABuilder with minimal cache settings */

121

static JDABuilder createLight(String token);

122

123

/** Create JDABuilder with all cache enabled */

124

static JDABuilder create(String token);

125

126

/** Set bot token */

127

JDABuilder setToken(String token);

128

129

/** Enable specific gateway intents */

130

JDABuilder enableIntents(GatewayIntent... intents);

131

JDABuilder enableIntents(Collection<GatewayIntent> intents);

132

133

/** Disable specific gateway intents */

134

JDABuilder disableIntents(GatewayIntent... intents);

135

JDABuilder disableIntents(Collection<GatewayIntent> intents);

136

137

/** Set all enabled intents */

138

JDABuilder setEnabledIntents(Collection<GatewayIntent> intents);

139

140

/** Enable cache flags */

141

JDABuilder enableCache(CacheFlag... flags);

142

JDABuilder enableCache(Collection<CacheFlag> flags);

143

144

/** Disable cache flags */

145

JDABuilder disableCache(CacheFlag... flags);

146

JDABuilder disableCache(Collection<CacheFlag> flags);

147

148

/** Set member cache policy */

149

JDABuilder setMemberCachePolicy(MemberCachePolicy policy);

150

151

/** Set chunking filter */

152

JDABuilder setChunkingFilter(ChunkingFilter filter);

153

154

/** Set event manager */

155

JDABuilder setEventManager(IEventManager manager);

156

157

/** Add event listeners */

158

JDABuilder addEventListeners(Object... listeners);

159

160

/** Set initial online status */

161

JDABuilder setStatus(OnlineStatus status);

162

163

/** Set initial activity */

164

JDABuilder setActivity(Activity activity);

165

166

/** Set whether to idle on startup */

167

JDABuilder setIdle(boolean idle);

168

169

/** Set HTTP client builder */

170

JDABuilder setHttpClientBuilder(OkHttpClient.Builder builder);

171

172

/** Set HTTP client */

173

JDABuilder setHttpClient(OkHttpClient client);

174

175

/** Set WebSocket factory */

176

JDABuilder setWebsocketFactory(WebSocketFactory factory);

177

178

/** Set rate limit scheduler */

179

JDABuilder setRateLimitScheduler(ScheduledExecutorService scheduler);

180

181

/** Set callback thread pool */

182

JDABuilder setCallbackPool(ExecutorService executor);

183

184

/** Set event thread pool */

185

JDABuilder setEventPool(ExecutorService executor);

186

187

/** Set audio thread pool */

188

JDABuilder setAudioPool(ScheduledExecutorService executor);

189

190

/** Set shard information for sharded bots */

191

JDABuilder useSharding(int shardId, int shardTotal);

192

193

/** Set session controller for shard coordination */

194

JDABuilder setSessionController(SessionController controller);

195

196

/** Set voice dispatch interceptor */

197

JDABuilder setVoiceDispatchInterceptor(VoiceDispatchInterceptor interceptor);

198

199

/** Set audio send factory */

200

JDABuilder setAudioSendFactory(IAudioSendFactory factory);

201

202

/** Set maximum reconnect delay */

203

JDABuilder setMaxReconnectDelay(int maxReconnectDelay);

204

205

/** Set large guild threshold */

206

JDABuilder setLargeThreshold(int threshold);

207

208

/** Set maximum buffer size */

209

JDABuilder setMaxBufferSize(int bufferSize);

210

211

/** Set compression type */

212

JDABuilder setCompression(Compression compression);

213

214

/** Set gateway encoding */

215

JDABuilder setEncoding(GatewayEncoding encoding);

216

217

/** Enable/disable specific config flags */

218

JDABuilder setFlag(ConfigFlag flag, boolean enable);

219

220

/** Set context map for request context */

221

JDABuilder setContextMap(ConcurrentMap<String, String> map);

222

223

/** Build and create JDA instance */

224

JDA build() throws LoginException, InterruptedException;

225

}

226

```

227

228

**Usage Examples:**

229

230

```java

231

import net.dv8tion.jda.api.JDABuilder;

232

import net.dv8tion.jda.api.requests.GatewayIntent;

233

import java.util.EnumSet;

234

235

// Basic bot setup

236

JDA jda = JDABuilder.createDefault("BOT_TOKEN")

237

.addEventListeners(new MyEventListener())

238

.build();

239

240

// Message logging bot

241

JDA messageBot = JDABuilder.createLight("BOT_TOKEN",

242

EnumSet.of(GatewayIntent.GUILD_MESSAGES, GatewayIntent.MESSAGE_CONTENT))

243

.addEventListeners(new MessageLogger())

244

.setStatus(OnlineStatus.ONLINE)

245

.setActivity(Activity.watching("for messages"))

246

.build();

247

248

// Slash command bot (no special intents needed)

249

JDA slashBot = JDABuilder.createLight("BOT_TOKEN", Collections.emptyList())

250

.addEventListeners(new SlashCommandHandler())

251

.setStatus(OnlineStatus.ONLINE)

252

.build();

253

254

// Advanced configuration

255

JDA advancedBot = JDABuilder.createDefault("BOT_TOKEN")

256

.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES)

257

.setMemberCachePolicy(MemberCachePolicy.VOICE.or(MemberCachePolicy.OWNER))

258

.setChunkingFilter(ChunkingFilter.NONE)

259

.disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS)

260

.setLargeThreshold(50)

261

.addEventListeners(new MyEventListener())

262

.build();

263

```

264

265

### Connection Status

266

267

Enumeration representing the various states of the JDA connection lifecycle.

268

269

```java { .api }

270

/**

271

* Represents the connection status of JDA and its Main WebSocket.

272

*/

273

enum Status {

274

/** JDA is currently setting up supporting systems like the AudioSystem */

275

INITIALIZING(true),

276

277

/** JDA has finished setting up supporting systems and is ready to log in */

278

INITIALIZED(true),

279

280

/** JDA is currently attempting to log in */

281

LOGGING_IN(true),

282

283

/** JDA is currently attempting to connect its websocket to Discord */

284

CONNECTING_TO_WEBSOCKET(true),

285

286

/** JDA has successfully connected its websocket to Discord and is sending authentication */

287

IDENTIFYING_SESSION(true),

288

289

/** JDA has sent authentication to discord and is awaiting confirmation */

290

AWAITING_LOGIN_CONFIRMATION(true),

291

292

/** JDA is populating internal objects */

293

LOADING_SUBSYSTEMS(true),

294

295

/** JDA has finished loading everything and is firing events */

296

CONNECTED(true),

297

298

/** JDA is ready to receive events and dispatch them to listeners */

299

READY(true),

300

301

/** JDA WebSocket connection was closed and a reconnect is being attempted */

302

DISCONNECTED(false),

303

304

/** JDA session has been added to SessionController queue for reconnect */

305

RECONNECTING(false),

306

307

/** JDA is currently shutting down */

308

SHUTTING_DOWN(false),

309

310

/** JDA has finished shutting down and cannot be used anymore */

311

SHUTDOWN(false),

312

313

/** An error occurred during login */

314

FAILED_TO_LOGIN(false);

315

316

/** Whether this status indicates the session is connected to Discord */

317

boolean isConnected();

318

}

319

```

320

321

### Shard Information

322

323

Information about the current shard for multi-shard deployments.

324

325

```java { .api }

326

/**

327

* Represents shard information for sharded JDA instances.

328

*/

329

class ShardInfo {

330

/** Get shard ID (0-based) */

331

int getShardId();

332

333

/** Get total number of shards */

334

int getShardTotal();

335

336

/** Get shard string representation (id/total) */

337

String getShardString();

338

}

339

```

340

341

### Bot User Information

342

343

Information about the bot's own user account.

344

345

```java { .api }

346

/**

347

* Represents the bot's own user account with additional bot-specific information.

348

*/

349

interface SelfUser extends User {

350

/** Get bot application ID */

351

long getApplicationIdLong();

352

String getApplicationId();

353

354

/** Check if bot is verified */

355

boolean isVerified();

356

357

/** Check if bot can be added by users */

358

boolean isMfaEnabled();

359

}

360

```