fix(StreamDispatcher): check if resource has ended

This commit is contained in:
DevAndromeda 2021-08-23 18:36:03 +05:45
parent edc54bb38a
commit dd91244e43
No known key found for this signature in database
GPG key ID: FA40E3EC5CB6DCD6
2 changed files with 8 additions and 1 deletions

View file

@ -19,7 +19,13 @@ client.on("error", console.error);
client.on("warn", console.warn); client.on("warn", console.warn);
// instantiate the player // 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) => { player.on("error", (queue, error) => {
console.log(`[${queue.guild.name}] Error emitted from the queue: ${error.message}`); console.log(`[${queue.guild.name}] Error emitted from the queue: ${error.message}`);

View file

@ -184,6 +184,7 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
*/ */
async playStream(resource: AudioResource<Track> = this.audioResource) { async playStream(resource: AudioResource<Track> = this.audioResource) {
if (!resource) throw new PlayerError("Audio resource is not available!", ErrorStatusCode.NO_AUDIO_RESOURCE); 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.audioResource) this.audioResource = resource;
if (this.voiceConnection.state.status !== VoiceConnectionStatus.Ready) { if (this.voiceConnection.state.status !== VoiceConnectionStatus.Ready) {
try { try {