discord-player
Advanced tools
Comparing version 1.3.10 to 1.4.0
{ | ||
"name": "discord-player", | ||
"version": "1.3.10", | ||
"version": "1.4.0", | ||
"description": "Complete framework to facilitate music commands using discord.js v12", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -94,5 +94,6 @@ const ytdl = require('ytdl-core'); | ||
* @param {string} songName The name of the song to play. | ||
* @param {User} requestedBy The user who requested the song. | ||
* @returns {Promise<Song>} | ||
*/ | ||
play(voiceChannel, songName) { | ||
play(voiceChannel, songName, requestedBy) { | ||
this.queues = this.queues.filter((g) => g.guildID !== voiceChannel.id); | ||
@@ -110,3 +111,3 @@ return new Promise(async (resolve, reject) => { | ||
queue.connection = connection; | ||
let song = new Song(video, queue); | ||
let song = new Song(video, queue, requestedBy); | ||
queue.songs.push(song); | ||
@@ -210,5 +211,6 @@ // Add the queue to the list | ||
* @param {string} songName The name of the song to add to the queue. | ||
* @param {User} requestedBy The user who requested the song. | ||
* @returns {Promise<Song>} | ||
*/ | ||
addToQueue(guildID, songName){ | ||
addToQueue(guildID, songName, requestedBy){ | ||
return new Promise(async(resolve, reject) => { | ||
@@ -221,3 +223,3 @@ // Gets guild queue | ||
if(!video) return reject('Song not found'); | ||
let song = new Song(video, queue); | ||
let song = new Song(video, queue, requestedBy); | ||
// Updates queue | ||
@@ -320,2 +322,50 @@ queue.songs.push(song); | ||
/** | ||
* Shuffles the guild queue. | ||
* @param {string} guildID | ||
* @returns {Promise<Void>} | ||
*/ | ||
shuffle(guildID){ | ||
return new Promise(async(resolve, reject) => { | ||
// Gets guild queue | ||
let queue = this.queues.find((g) => g.guildID === guildID); | ||
if(!queue) return reject('Not playing'); | ||
// Shuffle the queue (except the first song) | ||
let currentSong = queue.songs.shift(); | ||
queue.songs = queue.songs.sort(() => Math.random() - 0.5); | ||
queue.songs.unshift(currentSong); | ||
// Resolve | ||
resolve(); | ||
}); | ||
} | ||
/** | ||
* 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<Song|null>} | ||
*/ | ||
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. | ||
@@ -322,0 +372,0 @@ * @ignore |
@@ -9,3 +9,3 @@ /** | ||
*/ | ||
constructor(video, queue) { | ||
constructor(video, queue, requestedBy) { | ||
/** | ||
@@ -47,6 +47,11 @@ * Song name. | ||
/** | ||
* The queue in which the song is | ||
* The queue in which the song is. | ||
* @type {Queue} | ||
*/ | ||
this.queue = queue; | ||
/** | ||
* The user who requested that song. | ||
* @type {User} | ||
*/ | ||
this.requestedBy = requestedBy; | ||
} | ||
@@ -53,0 +58,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34468
587