Wait till JDA is ready within BotConfig.java

java-rewrite
Hammy 3 years ago
parent fbbe1ef005
commit e7c262f3f5

@ -4,31 +4,25 @@ import io.micronaut.context.annotation.Value;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import me.goudham.command.CommandManager;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
@Singleton
public class EnsoBot implements Bot {
private final JDA jda;
private final Guild guild;
private final boolean registerCommands;
private final CommandManager commandManager;
@Inject
public EnsoBot(JDA jda,
Guild guild,
public EnsoBot(Guild guild,
@Value("${bot.config.registerCommands}") boolean registerCommands,
CommandManager commandManager) {
this.jda = jda;
this.guild = guild;
this.registerCommands = registerCommands;
this.commandManager = commandManager;
}
@Override
public void startup() throws InterruptedException {
jda.awaitReady();
public void startup() {
if (registerCommands) {
commandManager.registerSlashCommands(guild);
} else {

@ -42,7 +42,7 @@ public class BotConfig {
@Singleton
@Order(1)
public JDA jda(CommandHandler commandHandler) throws LoginException {
public JDA jda(CommandHandler commandHandler) throws LoginException, InterruptedException {
return JDABuilder
.createDefault(token)
.setActivity(Activity.playing("With Hamothy"))
@ -59,15 +59,15 @@ public class BotConfig {
GatewayIntent.GUILD_EMOJIS,
GatewayIntent.GUILD_MESSAGE_REACTIONS
)
).enableCache(CacheFlag.VOICE_STATE)
.build();
)
.enableCache(CacheFlag.VOICE_STATE)
.build()
.awaitReady();
}
@Singleton
@Order(2)
public Guild ownerGuild(JDA jda) throws InterruptedException {
jda.awaitStatus(JDA.Status.CONNECTED);
public Guild ownerGuild(JDA jda) {
Guild ownerGuild = jda.getGuildById(guildId);
if (ownerGuild == null) {
throw new RuntimeException("Owner Guild Not Found");

Loading…
Cancel
Save