From 1dbe22f872219524b9ecf981989694e195315d32 Mon Sep 17 00:00:00 2001 From: Androz2091 Date: Fri, 24 Apr 2020 17:20:48 +0200 Subject: [PATCH] feat: add remove method --- src/Player.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Player.js b/src/Player.js index c94c8a3..8ec0679 100644 --- a/src/Player.js +++ b/src/Player.js @@ -333,6 +333,35 @@ class Player { }); } + /** + * Removes a song from the queue + * @param {string} guildID + * @param {number|Song} song The index of the song to remove or the song to remove object. + * @returns {Promise} + */ + remove(guildID, song){ + return new Promise(async(resolve, reject) => { + // Gets guild queue + let queue = this.queues.find((g) => g.guildID === guildID); + if(!queue) return reject('Not playing'); + // Remove the song from the queue + let songFound = null; + if(typeof song === "number"){ + songFound = queue.songs[song]; + if(songFound){ + queue.songs = queue.songs.filter((s) => s !== songFound); + } + } else { + songFound = queue.songs.find((s) => s === song); + if(songFound){ + queue.songs = queue.songs.filter((s) => s !== songFound); + } + } + // Resolve + resolve(songFound); + }); + } + /** * Start playing songs in a guild. * @ignore