Fix: ensureConnectionReady raeumt kaputte Connection auf statt sie zurueckzugeben
This commit is contained in:
parent
f26f90e0dc
commit
8cef19f724
1 changed files with 18 additions and 9 deletions
|
|
@ -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);
|
||||
});
|
||||
return newConn;
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue