diff --git a/src/main/java/me/goudham/bot/EnsoBot.java b/src/main/java/me/goudham/bot/EnsoBot.java index d2c20555..1312bc3b 100644 --- a/src/main/java/me/goudham/bot/EnsoBot.java +++ b/src/main/java/me/goudham/bot/EnsoBot.java @@ -4,7 +4,6 @@ import io.micronaut.context.annotation.Value; import jakarta.inject.Inject; import jakarta.inject.Singleton; import me.goudham.command.CommandManager; -import me.goudham.listener.SlashCommandListener; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; @@ -29,7 +28,6 @@ public class EnsoBot implements Bot { @Override public void startup() throws InterruptedException { jda.awaitReady(); - addEventListeners(); if (registerCommands) { commandManager.registerSlashCommands(guild); @@ -37,8 +35,4 @@ public class EnsoBot implements Bot { commandManager.populateCommandMap(); } } - - private void addEventListeners() { - jda.addEventListener(new SlashCommandListener(commandManager)); - } } diff --git a/src/main/java/me/goudham/config/BotConfig.java b/src/main/java/me/goudham/config/BotConfig.java index 221d3d87..12fb3f90 100644 --- a/src/main/java/me/goudham/config/BotConfig.java +++ b/src/main/java/me/goudham/config/BotConfig.java @@ -11,7 +11,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import javax.security.auth.login.LoginException; +import me.goudham.command.CommandHandler; import me.goudham.listener.OnReadyListener; +import me.goudham.listener.SlashCommandListener; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Activity; @@ -38,25 +40,16 @@ public class BotConfig { return new HashMap<>(); } - @Singleton - @Order(2) - public Guild ownerGuild(JDA jda) throws InterruptedException { - jda.awaitStatus(JDA.Status.CONNECTED); - - Guild ownerGuild = jda.getGuildById(guildId); - if (ownerGuild == null) { - throw new RuntimeException("Owner Guild Not Found"); - } - return ownerGuild; - } - @Singleton @Order(1) - public JDA jda() throws LoginException { + public JDA jda(CommandHandler commandHandler) throws LoginException { return JDABuilder .createDefault(token) .setActivity(Activity.playing("With Hamothy")) - .addEventListeners(new OnReadyListener()) + .addEventListeners( + new OnReadyListener(), + new SlashCommandListener(commandHandler) + ) .enableIntents( List.of( GatewayIntent.GUILD_MEMBERS, @@ -69,4 +62,16 @@ public class BotConfig { ).enableCache(CacheFlag.VOICE_STATE) .build(); } + + @Singleton + @Order(2) + public Guild ownerGuild(JDA jda) throws InterruptedException { + jda.awaitStatus(JDA.Status.CONNECTED); + + Guild ownerGuild = jda.getGuildById(guildId); + if (ownerGuild == null) { + throw new RuntimeException("Owner Guild Not Found"); + } + return ownerGuild; + } }