Fix: ensureConnectionReady raeumt kaputte Connection auf statt sie zurueckzugeben

This commit is contained in:
Claude Code 2026-03-05 00:31:55 +01:00
parent f26f90e0dc
commit 8cef19f724

View file

@ -518,26 +518,29 @@ async function handleCommand(message: Message, content: string) {
}
async function ensureConnectionReady(connection: VoiceConnection, channelId: string, guildId: string, guild: any): Promise<VoiceConnection> {
// Versuch 1: Warten ob bestehende Connection ready wird
try {
await entersState(connection, VoiceConnectionStatus.Ready, 15_000);
console.log(`${new Date().toISOString()} | VoiceConnection ready`);
return connection;
} catch (e) {
console.warn(`${new Date().toISOString()} | VoiceConnection not ready, trying rejoin...`, e);
console.warn(`${new Date().toISOString()} | VoiceConnection not ready, trying rejoin...`);
}
// Versuch 2: Rejoin
try {
connection.rejoin({ channelId, selfDeaf: false, selfMute: false });
await entersState(connection, VoiceConnectionStatus.Ready, 15_000);
console.log(`${new Date().toISOString()} | VoiceConnection ready after rejoin`);
return connection;
} catch (e2) {
console.error(`${new Date().toISOString()} | VoiceConnection still not ready after rejoin`, e2);
console.warn(`${new Date().toISOString()} | VoiceConnection still not ready after rejoin`);
}
try {
connection.destroy();
} catch {}
// Versuch 3: Komplett neu verbinden
try { connection.destroy(); } catch {}
guildAudioState.delete(guildId);
const newConn = joinVoiceChannel({
channelId,
guildId,
@ -545,10 +548,16 @@ async function ensureConnectionReady(connection: VoiceConnection, channelId: str
selfMute: false,
selfDeaf: false
});
await entersState(newConn, VoiceConnectionStatus.Ready, 15_000).catch((e3) => {
console.error(`${new Date().toISOString()} | VoiceConnection not ready after fresh join`, e3);
});
try {
await entersState(newConn, VoiceConnectionStatus.Ready, 15_000);
console.log(`${new Date().toISOString()} | VoiceConnection ready after fresh join`);
return newConn;
} catch (e3) {
console.error(`${new Date().toISOString()} | VoiceConnection failed after all attempts, cleaning up`);
try { newConn.destroy(); } catch {}
guildAudioState.delete(guildId);
throw new Error('Voice connection failed after 3 attempts');
}
}
function attachVoiceLifecycle(state: GuildAudioState, guild: any) {