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.Inject;
import jakarta.inject.Singleton; import jakarta.inject.Singleton;
import me.goudham.command.CommandManager; import me.goudham.command.CommandManager;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
@Singleton @Singleton
public class EnsoBot implements Bot { public class EnsoBot implements Bot {
private final JDA jda;
private final Guild guild; private final Guild guild;
private final boolean registerCommands; private final boolean registerCommands;
private final CommandManager commandManager; private final CommandManager commandManager;
@Inject @Inject
public EnsoBot(JDA jda, public EnsoBot(Guild guild,
Guild guild,
@Value("${bot.config.registerCommands}") boolean registerCommands, @Value("${bot.config.registerCommands}") boolean registerCommands,
CommandManager commandManager) { CommandManager commandManager) {
this.jda = jda;
this.guild = guild; this.guild = guild;
this.registerCommands = registerCommands; this.registerCommands = registerCommands;
this.commandManager = commandManager; this.commandManager = commandManager;
} }
@Override @Override
public void startup() throws InterruptedException { public void startup() {
jda.awaitReady();
if (registerCommands) { if (registerCommands) {
commandManager.registerSlashCommands(guild); commandManager.registerSlashCommands(guild);
} else { } else {

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

Loading…
Cancel
Save