mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-19 19:45:14 +00:00
Improve JDA initialization with enhanced error handling and connection validation
This commit is contained in:
parent
f325e22f0a
commit
6a0e4ed629
1 changed files with 15 additions and 9 deletions
|
|
@ -43,19 +43,19 @@ public class DiscordManager {
|
|||
}
|
||||
|
||||
try {
|
||||
jda = JDABuilder.createDefault(token)
|
||||
.enableIntents(
|
||||
GatewayIntent.MESSAGE_CONTENT,
|
||||
GatewayIntent.GUILD_MEMBERS
|
||||
)
|
||||
.setMemberCachePolicy(MemberCachePolicy.ALL)
|
||||
.addEventListeners(new DiscordEventHandler())
|
||||
.build();
|
||||
|
||||
// Blocks until JDA is ready
|
||||
try (ExecutorService executor = Executors.newSingleThreadExecutor(r -> new Thread(r, "DMCC-FutureChecker"))) {
|
||||
CompletableFuture<Void> readyFuture = CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
jda = JDABuilder.createDefault(token)
|
||||
.enableIntents(
|
||||
GatewayIntent.MESSAGE_CONTENT,
|
||||
GatewayIntent.GUILD_MEMBERS
|
||||
)
|
||||
.setMemberCachePolicy(MemberCachePolicy.ALL)
|
||||
.addEventListeners(new DiscordEventHandler())
|
||||
.build();
|
||||
|
||||
jda.awaitReady();
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error(I18nManager.getDmccTranslation("discord.manager.init_interrupted"), e);
|
||||
|
|
@ -77,6 +77,10 @@ public class DiscordManager {
|
|||
LOGGER.error(I18nManager.getDmccTranslation("discord.manager.init_interrupted"), e);
|
||||
}
|
||||
|
||||
if (jda == null || jda.getStatus() != JDA.Status.CONNECTED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Blocks until commands are updated
|
||||
try (ExecutorService executor = Executors.newSingleThreadExecutor(r -> new Thread(r, "DMCC-FutureChecker"))) {
|
||||
List<CommandData> commands = new ArrayList<>();
|
||||
|
|
@ -121,6 +125,8 @@ public class DiscordManager {
|
|||
} catch (Exception ignored) {
|
||||
}
|
||||
jda.shutdownNow();
|
||||
|
||||
jda = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue