From fdc9df2946d32c18db04483157c5d6a2036a530b Mon Sep 17 00:00:00 2001 From: loki5512344 Date: Sun, 12 Jul 2026 23:59:38 +0200 Subject: [PATCH] fix: add audio manager fallback and debug logging for radio voice connection --- .../loki/feature/radio/RadioManager.java | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/main/java/creator/loki/feature/radio/RadioManager.java b/src/main/java/creator/loki/feature/radio/RadioManager.java index 76bdbb6..f37716a 100644 --- a/src/main/java/creator/loki/feature/radio/RadioManager.java +++ b/src/main/java/creator/loki/feature/radio/RadioManager.java @@ -68,7 +68,10 @@ public class RadioManager { var finalState = radioStates.computeIfAbsent(guildId, id -> new GuildRadioState()); finalState.streamUrl = getRadioUrl(guildId); Guild guild = radioJda.getGuildById(guildId); - if (guild == null) return; + if (guild == null) { + logger.warn("Radio: guild {} not found in radio bot cache", guildId); + return; + } var client = lavalinkManager.getClient(); if (client != null && !VoiceHelper.waitForCondition( @@ -79,11 +82,43 @@ public class RadioManager { logger, "Radio: Lavalink node not ready for guild " + guildId); return; } - guild.getJDA().getDirectAudioController().connect(guild.getVoiceChannelById(channelId)); + var vc = guild.getVoiceChannelById(channelId); + if (vc == null) { + logger.warn("Radio: voice channel {} not found in guild {}", channelId, guildId); + return; + } + logger.debug("Radio: connecting to channel {}/{} in guild {}", vc.getName(), channelId, guildId); + guild.getJDA().getDirectAudioController().connect(vc); + if (!guild.getAudioManager().isConnected()) { + guild.getAudioManager().openAudioConnection(vc); + } var self = guild.getMember(guild.getJDA().getSelfUser()); - if (!VoiceHelper.waitForCondition( - () -> self.getVoiceState().inAudioChannel(), VOICE_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { - LoggerDecorator.warn(logger, "Radio: voice connection timeout for guild " + guildId); + if (self == null) { + logger.warn("Radio: self member is null for guild {}", guildId); + return; + } + logger.debug( + "Radio: initial voice state for guild {}: inAudioChannel={}", + guildId, + self.getVoiceState().inAudioChannel()); + for (int i = 0; i < 25; i++) { + if (self.getVoiceState().inAudioChannel()) break; + logger.debug( + "Radio: waiting for voice state in guild {} (attempt {})", guildId, i + 1); + try { + Thread.sleep(200); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return; + } + } + if (!self.getVoiceState().inAudioChannel()) { + logger.warn( + "Radio: voice connection timeout for guild {} (channel: {})", + guildId, + self.getVoiceState().getChannel() != null + ? self.getVoiceState().getChannel().getId() + : "null"); return; } var link = lavalinkManager.getOrCreateLink(guildId);