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) };