diff --git a/src/main/java/me/goudham/bot/EnsoBot.java b/src/main/java/me/goudham/bot/EnsoBot.java index f6e88fa4..d8601018 100644 --- a/src/main/java/me/goudham/bot/EnsoBot.java +++ b/src/main/java/me/goudham/bot/EnsoBot.java @@ -3,6 +3,7 @@ package me.goudham.bot; 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; @@ -22,6 +23,11 @@ public class EnsoBot implements Bot { @Override public void startup() throws InterruptedException { jda.awaitReady(); + addEventListeners(); commandManager.registerSlashCommands(guild); } + + private void addEventListeners() { + jda.addEventListener(new SlashCommandListener(commandManager)); + } } diff --git a/src/main/java/me/goudham/listener/SlashCommandListener.java b/src/main/java/me/goudham/listener/SlashCommandListener.java new file mode 100644 index 00000000..8c1f0c06 --- /dev/null +++ b/src/main/java/me/goudham/listener/SlashCommandListener.java @@ -0,0 +1,24 @@ +package me.goudham.listener; + +import jakarta.inject.Inject; +import jakarta.inject.Singleton; +import me.goudham.command.CommandManager; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.jetbrains.annotations.NotNull; + +@Singleton +public class SlashCommandListener extends ListenerAdapter { + private final CommandManager commandManager; + + @Inject + public SlashCommandListener(CommandManager commandManager) { + this.commandManager = commandManager; + } + + @Override + public void onSlashCommand(@NotNull SlashCommandEvent event) { + if (event.getGuild() == null) return; + commandManager.handleSlashCommandEvent(event); + } +}