From 9a18499aab80f3b97b5fb8cbd09af1c1525304b2 Mon Sep 17 00:00:00 2001 From: LOLBRUHNICE <65208589+LOLBRUHNICE@users.noreply.github.com> Date: Sun, 19 Sep 2021 14:32:45 +0800 Subject: [PATCH] handle voice connection destroy error --- src/VoiceInterface/StreamDispatcher.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/VoiceInterface/StreamDispatcher.ts b/src/VoiceInterface/StreamDispatcher.ts index cd4567f..0624b53 100644 --- a/src/VoiceInterface/StreamDispatcher.ts +++ b/src/VoiceInterface/StreamDispatcher.ts @@ -74,13 +74,21 @@ class StreamDispatcher extends EventEmitter { try { await entersState(this.voiceConnection, VoiceConnectionStatus.Connecting, this.connectionTimeout); } catch { - this.voiceConnection.destroy(); + try { + this.voiceConnection.destroy(); + } catch (err) { + this.emit("error", err as AudioPlayerError); + } } } else if (this.voiceConnection.rejoinAttempts < 5) { await Util.wait((this.voiceConnection.rejoinAttempts + 1) * 5000); this.voiceConnection.rejoin(); } else { - this.voiceConnection.destroy(); + try { + this.voiceConnection.destroy(); + } catch (err) { + this.emit("error", err as AudioPlayerError); + } } } else if (newState.status === VoiceConnectionStatus.Destroyed) { this.end(); @@ -89,7 +97,13 @@ class StreamDispatcher extends EventEmitter { try { await entersState(this.voiceConnection, VoiceConnectionStatus.Ready, this.connectionTimeout); } catch { - if (this.voiceConnection.state.status !== VoiceConnectionStatus.Destroyed) this.voiceConnection.destroy(); + if (this.voiceConnection.state.status !== VoiceConnectionStatus.Destroyed) { + try { + this.voiceConnection.destroy(); + } catch (err) { + this.emit("error", err as AudioPlayerError); + } + } } finally { this.readyLock = false; }