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 <noreply@anthropic.com>
This commit is contained in:
Daniel 2026-03-06 01:49:17 +01:00
parent a13765d5b6
commit 20ea13d71f

View file

@ -239,6 +239,8 @@ async function ensureConnectionReady(connection: VoiceConnection, channelId: str
guildAudioState.delete(guildId); guildAudioState.delete(guildId);
console.log(`${SB} Creating fresh connection (attempt 3)...`); console.log(`${SB} Creating fresh connection (attempt 3)...`);
const newConn = joinVoiceChannel({ channelId, guildId, adapterCreator: debugAdapterCreator(guild), selfMute: false, selfDeaf: false }); 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; } 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'); } 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) { if (!state) {
console.log(`${SB} No existing audio state, creating new connection...`); console.log(`${SB} No existing audio state, creating new connection...`);
const connection = joinVoiceChannel({ channelId, guildId, adapterCreator: debugAdapterCreator(guild), selfMute: false, selfDeaf: false }); 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 } }); const player = createAudioPlayer({ behaviors: { noSubscriber: NoSubscriberBehavior.Play } });
connection.subscribe(player); connection.subscribe(player);
state = { connection, player, guildId, channelId, currentVolume: getPersistedVolume(guildId) }; state = { connection, player, guildId, channelId, currentVolume: getPersistedVolume(guildId) };