From dd91244e433e83c3c2a60657fe448d785ecbf33c Mon Sep 17 00:00:00 2001 From: DevAndromeda <46562212+DevAndromeda@users.noreply.github.com> Date: Mon, 23 Aug 2021 18:36:03 +0545 Subject: [PATCH] fix(StreamDispatcher): check if resource has ended --- example/music-bot/index.js | 8 +++++++- src/VoiceInterface/StreamDispatcher.ts | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/example/music-bot/index.js b/example/music-bot/index.js index b707114..d02659d 100644 --- a/example/music-bot/index.js +++ b/example/music-bot/index.js @@ -19,7 +19,13 @@ client.on("error", console.error); client.on("warn", console.warn); // instantiate the player -const player = new Player(client); +const player = new Player(client, { + ytdlOptions: { + headers: { + cookie: process.env.YT_COOKIE + } + } +}); player.on("error", (queue, error) => { console.log(`[${queue.guild.name}] Error emitted from the queue: ${error.message}`); diff --git a/src/VoiceInterface/StreamDispatcher.ts b/src/VoiceInterface/StreamDispatcher.ts index 19f6050..cd4567f 100644 --- a/src/VoiceInterface/StreamDispatcher.ts +++ b/src/VoiceInterface/StreamDispatcher.ts @@ -184,6 +184,7 @@ class StreamDispatcher extends EventEmitter { */ async playStream(resource: AudioResource = this.audioResource) { if (!resource) throw new PlayerError("Audio resource is not available!", ErrorStatusCode.NO_AUDIO_RESOURCE); + if (resource.ended) return void this.emit("error", new PlayerError("Cannot play a resource that has already ended.") as unknown as AudioPlayerError); if (!this.audioResource) this.audioResource = resource; if (this.voiceConnection.state.status !== VoiceConnectionStatus.Ready) { try {