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> {
|
async function ensureConnectionReady(connection: VoiceConnection, channelId: string, guildId: string, guild: any): Promise<VoiceConnection> {
|
||||||
|
// Versuch 1: Warten ob bestehende Connection ready wird
|
||||||
try {
|
try {
|
||||||
await entersState(connection, VoiceConnectionStatus.Ready, 15_000);
|
await entersState(connection, VoiceConnectionStatus.Ready, 15_000);
|
||||||
console.log(`${new Date().toISOString()} | VoiceConnection ready`);
|
console.log(`${new Date().toISOString()} | VoiceConnection ready`);
|
||||||
return connection;
|
return connection;
|
||||||
} catch (e) {
|
} 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 {
|
try {
|
||||||
connection.rejoin({ channelId, selfDeaf: false, selfMute: false });
|
connection.rejoin({ channelId, selfDeaf: false, selfMute: false });
|
||||||
await entersState(connection, VoiceConnectionStatus.Ready, 15_000);
|
await entersState(connection, VoiceConnectionStatus.Ready, 15_000);
|
||||||
console.log(`${new Date().toISOString()} | VoiceConnection ready after rejoin`);
|
console.log(`${new Date().toISOString()} | VoiceConnection ready after rejoin`);
|
||||||
return connection;
|
return connection;
|
||||||
} catch (e2) {
|
} 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 {
|
// Versuch 3: Komplett neu verbinden
|
||||||
connection.destroy();
|
try { connection.destroy(); } catch {}
|
||||||
} catch {}
|
guildAudioState.delete(guildId);
|
||||||
|
|
||||||
const newConn = joinVoiceChannel({
|
const newConn = joinVoiceChannel({
|
||||||
channelId,
|
channelId,
|
||||||
guildId,
|
guildId,
|
||||||
|
|
@ -545,10 +548,16 @@ async function ensureConnectionReady(connection: VoiceConnection, channelId: str
|
||||||
selfMute: false,
|
selfMute: false,
|
||||||
selfDeaf: false
|
selfDeaf: false
|
||||||
});
|
});
|
||||||
await entersState(newConn, VoiceConnectionStatus.Ready, 15_000).catch((e3) => {
|
try {
|
||||||
console.error(`${new Date().toISOString()} | VoiceConnection not ready after fresh join`, e3);
|
await entersState(newConn, VoiceConnectionStatus.Ready, 15_000);
|
||||||
});
|
console.log(`${new Date().toISOString()} | VoiceConnection ready after fresh join`);
|
||||||
return newConn;
|
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) {
|
function attachVoiceLifecycle(state: GuildAudioState, guild: any) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue