handle null resource

This commit is contained in:
Snowflake107 2021-06-22 20:23:00 +05:45
parent f0259b39ce
commit 6e70970cc4

View file

@ -143,7 +143,7 @@ class Queue<T = unknown> {
this.connection.on("start", (resource) => { this.connection.on("start", (resource) => {
this.playing = true; this.playing = true;
if (!this._filtersUpdate) this.player.emit("trackStart", this, resource.metadata); if (!this._filtersUpdate) this.player.emit("trackStart", this, resource?.metadata ?? this.current);
this._filtersUpdate = false; this._filtersUpdate = false;
}); });
@ -151,7 +151,7 @@ class Queue<T = unknown> {
this.playing = false; this.playing = false;
if (this._filtersUpdate) return; if (this._filtersUpdate) return;
this._streamTime = 0; this._streamTime = 0;
this.previousTracks.push(resource.metadata); if (resource) this.previousTracks.push(resource.metadata);
if (!this.tracks.length && this.repeatMode === QueueRepeatMode.OFF) { if (!this.tracks.length && this.repeatMode === QueueRepeatMode.OFF) {
if (this.options.leaveOnEnd) this.destroy(); if (this.options.leaveOnEnd) this.destroy();
@ -385,6 +385,9 @@ class Queue<T = unknown> {
return await this.play(prev, { immediate: true }); return await this.play(prev, { immediate: true });
} }
/**
* Clear this queue
*/
clear() { clear() {
this.#watchDestroyed(); this.#watchDestroyed();
this.tracks = []; this.tracks = [];
@ -457,6 +460,11 @@ class Queue<T = unknown> {
}); });
} }
/**
* Private method to handle autoplay
* @param {Track} track The source track to find its similar track for autoplay
* @returns {Promise<void>}
*/
private async _handleAutoplay(track: Track): Promise<void> { private async _handleAutoplay(track: Track): Promise<void> {
this.#watchDestroyed(); this.#watchDestroyed();
if (!track || ![track.source, track.raw?.source].includes("youtube")) { if (!track || ![track.source, track.raw?.source].includes("youtube")) {