From 5c7c7e9f680302aa0d92c089c5a3b39c7118235a Mon Sep 17 00:00:00 2001 From: Braydon Date: Fri, 1 Dec 2023 23:46:48 -0500 Subject: [PATCH] will this work on the main thread? --- pom.xml | 4 +- .../license/service/DiscordService.java | 58 ++++++++++--------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/pom.xml b/pom.xml index 570e218..ead7aca 100644 --- a/pom.xml +++ b/pom.xml @@ -6,13 +6,13 @@ org.springframework.boot spring-boot-starter-parent - 3.1.0 + 3.2.0 me.braydon LicenseServer - 1.0.4 + 1.0.5 A simple open-source licensing server for your products. diff --git a/src/main/java/me/braydon/license/service/DiscordService.java b/src/main/java/me/braydon/license/service/DiscordService.java index 8e4a55e..59e2aa4 100644 --- a/src/main/java/me/braydon/license/service/DiscordService.java +++ b/src/main/java/me/braydon/license/service/DiscordService.java @@ -153,34 +153,36 @@ public final class DiscordService { return; } // Initialize the bot - new Thread(() -> { - long before = System.currentTimeMillis(); - log.info("Logging in..."); // Log that we're logging in - jda = JDABuilder.createDefault(token) - .enableIntents( - GatewayIntent.GUILD_MEMBERS - ).setStatus(OnlineStatus.DO_NOT_DISTURB) - .setActivity(Activity.watching("your licenses")) - .addEventListeners(new EventHandler()) - .build(); - try { - jda.awaitReady(); // Await JDA to be ready - - // Log that we're logged in - log.info("Logged into {} in {}ms", - jda.getSelfUser().getEffectiveName(), System.currentTimeMillis() - before - ); - - // Registering slash commands - jda.updateCommands().addCommands( - Commands.slash("license", "Manage one of your licenses") - .addOption(OptionType.STRING, "key", "The license key", true) - .addOption(OptionType.STRING, "product", "The product the license is for", true) - ).queue(); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - }, "Discord Bot Thread").start(); + long before = System.currentTimeMillis(); + log.info("Logging in..."); // Log that we're logging in + System.out.println("Step 1"); + jda = JDABuilder.createDefault(token) + .enableIntents( + GatewayIntent.GUILD_MEMBERS + ).setStatus(OnlineStatus.DO_NOT_DISTURB) + .setActivity(Activity.watching("your licenses")) + .addEventListeners(new EventHandler()) + .build(); + System.out.println("step 2"); + try { + jda.awaitReady(); // Await JDA to be ready + System.out.println("await complete"); + + // Log that we're logged in + log.info("Logged into {} in {}ms", + jda.getSelfUser().getEffectiveName(), System.currentTimeMillis() - before + ); + + // Registering slash commands + jda.updateCommands().addCommands( + Commands.slash("license", "Manage one of your licenses") + .addOption(OptionType.STRING, "key", "The license key", true) + .addOption(OptionType.STRING, "product", "The product the license is for", true) + ).queue(); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + System.out.println("finish"); } /**