Add SlashCommandListener.java

java-rewrite
Hammy 3 years ago
parent 0ddb21eec0
commit 2bb8ede97b

@ -3,6 +3,7 @@ package me.goudham.bot;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import jakarta.inject.Singleton; import jakarta.inject.Singleton;
import me.goudham.command.CommandManager; import me.goudham.command.CommandManager;
import me.goudham.listener.SlashCommandListener;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
@ -22,6 +23,11 @@ public class EnsoBot implements Bot {
@Override @Override
public void startup() throws InterruptedException { public void startup() throws InterruptedException {
jda.awaitReady(); jda.awaitReady();
addEventListeners();
commandManager.registerSlashCommands(guild); commandManager.registerSlashCommands(guild);
} }
private void addEventListeners() {
jda.addEventListener(new SlashCommandListener(commandManager));
}
} }

@ -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);
}
}
Loading…
Cancel
Save