From 20ea13d71fd5415f6d28e4438ec393ee94015bac Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 6 Mar 2026 01:49:17 +0100 Subject: [PATCH] debug: add connection stateChange + error listeners from creation Listen for state transitions and errors immediately after joinVoiceChannel, not just after ensureConnectionReady succeeds. This will show if the connection transitions at all internally or stays stuck at signalling. Co-Authored-By: Claude Opus 4.6 --- server/src/plugins/soundboard/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/src/plugins/soundboard/index.ts b/server/src/plugins/soundboard/index.ts index b29b94f..b11657f 100644 --- a/server/src/plugins/soundboard/index.ts +++ b/server/src/plugins/soundboard/index.ts @@ -239,6 +239,8 @@ async function ensureConnectionReady(connection: VoiceConnection, channelId: str guildAudioState.delete(guildId); console.log(`${SB} Creating fresh connection (attempt 3)...`); const newConn = joinVoiceChannel({ channelId, guildId, adapterCreator: debugAdapterCreator(guild), selfMute: false, selfDeaf: false }); + newConn.on('stateChange', (o: any, n: any) => console.log(`${SB} [fresh-conn] ${o.status} → ${n.status}`)); + newConn.on('error', (err: any) => console.error(`${SB} [fresh-conn] ERROR: ${err?.message ?? err}`)); try { await entersState(newConn, VoiceConnectionStatus.Ready, 15_000); console.log(`${SB} Connection ready (fresh)`); return newConn; } catch (e) { console.error(`${SB} All 3 connection attempts failed: ${(e as Error)?.message ?? e}`); try { newConn.destroy(); } catch {} guildAudioState.delete(guildId); throw new Error('Voice connection failed after 3 attempts'); } } @@ -338,6 +340,14 @@ async function playFilePath(guildId: string, channelId: string, filePath: string if (!state) { console.log(`${SB} No existing audio state, creating new connection...`); const connection = joinVoiceChannel({ channelId, guildId, adapterCreator: debugAdapterCreator(guild), selfMute: false, selfDeaf: false }); + // Debug: catch ALL state transitions and errors from the start + connection.on('stateChange', (o: any, n: any) => { + console.log(`${SB} [conn] ${o.status} → ${n.status}`); + // Log networking info if available + if (n.networking) console.log(`${SB} [conn] networking state: ${n.networking?.state?.code ?? 'unknown'}`); + }); + connection.on('error', (err: any) => console.error(`${SB} [conn] ERROR: ${err?.message ?? err}`)); + console.log(`${SB} Connection created, initial status=${connection.state.status}, state keys=${Object.keys(connection.state).join(',')}`); const player = createAudioPlayer({ behaviors: { noSubscriber: NoSubscriberBehavior.Play } }); connection.subscribe(player); state = { connection, player, guildId, channelId, currentVolume: getPersistedVolume(guildId) };