Update documentation and update addToQueue

This commit is contained in:
Androz2091 2020-06-24 18:07:17 +02:00
parent c1dae09be6
commit ef27a34a30

View file

@ -221,7 +221,7 @@ class Player {
* @param {Discord.VoiceChannel} voiceChannel The voice channel in which the track will be played * @param {Discord.VoiceChannel} voiceChannel The voice channel in which the track will be played
* @param {Track|string} track The name of the track to play * @param {Track|string} track The name of the track to play
* @param {Discord.User?} user The user who requested the track * @param {Discord.User?} user The user who requested the track
* @returns {any} The played track * @returns {any} The played content
* *
* @example * @example
* client.on('message', async (message) => { * client.on('message', async (message) => {
@ -450,8 +450,8 @@ class Player {
* Add a track to the guild queue * Add a track to the guild queue
* @param {Discord.Snowflake} guildID The ID of the guild where the track should be added * @param {Discord.Snowflake} guildID The ID of the guild where the track should be added
* @param {Track|string} trackName The name of the track to add to the queue * @param {Track|string} trackName The name of the track to add to the queue
* @param {Discord.User?} requestedBy The user who requested the track * @param {Discord.User?} user The user who requested the track
* @returns {Promise<Track>} The added track * @returns {any} The content added to the queue
* *
* @example * @example
* client.on('message', async (message) => { * client.on('message', async (message) => {
@ -463,33 +463,54 @@ class Player {
* let trackPlaying = client.player.isPlaying(message.guild.id); * let trackPlaying = client.player.isPlaying(message.guild.id);
* // If there's already a track being played * // If there's already a track being played
* if(trackPlaying){ * if(trackPlaying){
* // Add the track to the queue * const result = await client.player.addToQueue(message.guild.id, args.join(" "));
* let track = await client.player.addToQueue(message.guild.id, args[0]); * if(result.type === 'playlist'){
* message.channel.send(`${track.name} added to queue!`); * message.channel.send(`${result.tracks.length} songs added to the queue ${emotes.music}`);
* } else {
* message.channel.send(`${result.name} added to the queue ${emotes.music}`);
* }
* } else { * } else {
* // Else, play the track * // Else, play the track
* let track = await client.player.play(message.member.voice.channel, args[0]); * const result = await client.player.addToQueue(message.member.voice.channel, args[0]);
* message.channel.send(`Currently playing ${track.name}!`); * if(result.type === 'playlist'){
* message.channel.send(`${result.tracks.length} songs added to the queue ${emotes.music}\nCurrently playing **${result.tracks[0].name}**!`);
* } else {
* message.channel.send(`Currently playing ${result.name} ${emotes.music}`);
* }
* } * }
* } * }
* *
* }); * });
*/ */
addToQueue (guildID, track, requestedBy) { addToQueue (guildID, track, user) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
// Get guild queue // Get guild queue
const queue = this.queues.find((g) => g.guildID === guildID) const queue = this.queues.find((g) => g.guildID === guildID)
if (!queue) return reject(new Error('Not playing')) if (!queue) return reject(new Error('Not playing'))
// Search the track // Search the track
if (typeof track !== 'object') { let result = null
if (typeof track === 'object') {
track.requestedBy = user
result = track
// Add the track to the queue
queue.tracks.push(track)
} else if (typeof track === 'string') {
const results = await this.searchTracks(track) const results = await this.searchTracks(track)
track = results[0] if (results.length > 1) {
result = {
type: 'playlist',
tracks: results
}
} else {
result = results[0]
}
results.forEach((i) => {
i.requestedBy = user
queue.tracks.push(i)
})
} }
track.requestedBy = requestedBy // Resolve the result
// Update queue resolve(result)
queue.tracks.push(track)
// Resolve the track
resolve(track)
}) })
} }
@ -819,7 +840,7 @@ class Player {
* @ignore * @ignore
* @private * @private
* @param {Queue} queue The queue to play * @param {Queue} queue The queue to play
* @param {*} updateFilter Whether this method is called to update some ffmpeg filters * @param {Boolean} updateFilter Whether this method is called to update some ffmpeg filters
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
_playSouncloudStream (queue, updateFilter) { _playSouncloudStream (queue, updateFilter) {