Add music starting error

This commit is contained in:
Androz2091 2021-02-26 15:00:48 +01:00
parent ea84785e31
commit c594f48d0b

View file

@ -452,17 +452,27 @@ class Player extends EventEmitter {
* Moves to new voice channel * Moves to new voice channel
* @param {Discord.Message} message Message * @param {Discord.Message} message Message
* @param {Discord.VoiceChannel} channel Voice channel * @param {Discord.VoiceChannel} channel Voice channel
* @returns {boolean} Whether it succeed or not
*/ */
moveTo (message, channel) { moveTo (message, channel) {
if (!channel || channel.type !== 'voice') return if (!channel || channel.type !== 'voice') return
const queue = this.queues.find((g) => g.guildID === message.guild.id) const queue = this.queues.find((g) => g.guildID === message.guild.id)
if (!queue) return this.emit('error', 'NotPlaying', message) if (!queue) {
this.emit('error', 'NotPlaying', message)
return false
}
if (!queue.voiceConnection || !queue.voiceConnection.dispatcher) {
this.emit('error', 'MusicStarting', message)
return false
}
if (queue.voiceConnection.channel.id === channel.id) return if (queue.voiceConnection.channel.id === channel.id) return
queue.voiceConnection.dispatcher.pause() queue.voiceConnection.dispatcher.pause()
channel.join() channel.join()
.then(() => queue.voiceConnection.dispatcher.resume()) .then(() => queue.voiceConnection.dispatcher.resume())
.catch(() => this.emit('error', 'UnableToJoin', message)) .catch(() => this.emit('error', 'UnableToJoin', message))
return true
} }
/** /**
@ -755,43 +765,69 @@ class Player extends EventEmitter {
/** /**
* Pause the music in the server. * Pause the music in the server.
* @param {Discord.Message} message * @param {Discord.Message} message
* @returns {boolean} Whether it succeed or not
* @example * @example
* client.player.pause(message); * client.player.pause(message);
*/ */
pause (message) { pause (message) {
// Get guild queue // Get guild queue
const queue = this.queues.find((g) => g.guildID === message.guild.id) const queue = this.queues.find((g) => g.guildID === message.guild.id)
if (!queue) return this.emit('error', 'NotPlaying', message) if (!queue) {
this.emit('error', 'NotPlaying', message)
return false
}
if (!queue.voiceConnection || !queue.voiceConnection.dispatcher) {
this.emit('error', 'MusicStarting', message)
return false
}
// Pause the dispatcher // Pause the dispatcher
queue.voiceConnection.dispatcher.pause() queue.voiceConnection.dispatcher.pause()
queue.paused = true queue.paused = true
return true
} }
/** /**
* Resume the music in the server. * Resume the music in the server.
* @param {Discord.Message} message * @param {Discord.Message} message
* @returns {boolean} Whether it succeed or not
* @example * @example
* client.player.resume(message); * client.player.resume(message);
*/ */
resume (message) { resume (message) {
// Get guild queue // Get guild queue
const queue = this.queues.find((g) => g.guildID === message.guild.id) const queue = this.queues.find((g) => g.guildID === message.guild.id)
if (!queue) return this.emit('error', 'NotPlaying', message) if (!queue) {
this.emit('error', 'NotPlaying', message)
return false
}
if (!queue.voiceConnection || !queue.voiceConnection.dispatcher) {
this.emit('error', 'MusicStarting', message)
return false
}
// Resume the dispatcher // Resume the dispatcher
queue.voiceConnection.dispatcher.resume() queue.voiceConnection.dispatcher.resume()
queue.paused = false queue.paused = false
return true
} }
/** /**
* Stop the music in the server. * Stop the music in the server.
* @param {Discord.Message} message * @param {Discord.Message} message
* @returns {boolean} Whether it succeed or not
* @example * @example
* client.player.stop(message); * client.player.stop(message);
*/ */
stop (message) { stop (message) {
// Get guild queue // Get guild queue
const queue = this.queues.find((g) => g.guildID === message.guild.id) const queue = this.queues.find((g) => g.guildID === message.guild.id)
if (!queue) return this.emit('error', 'NotPlaying', message) if (!queue) {
this.emit('error', 'NotPlaying', message)
return false
}
if (!queue.voiceConnection || !queue.voiceConnection.dispatcher) {
this.emit('error', 'MusicStarting', message)
return false
}
// Stop the dispatcher // Stop the dispatcher
queue.stopped = true queue.stopped = true
queue.tracks = [] queue.tracks = []
@ -799,22 +835,32 @@ class Player extends EventEmitter {
queue.voiceConnection.dispatcher.end() queue.voiceConnection.dispatcher.end()
if (this.options.leaveOnStop) queue.voiceConnection.channel.leave() if (this.options.leaveOnStop) queue.voiceConnection.channel.leave()
this.queues.delete(message.guild.id) this.queues.delete(message.guild.id)
return true
} }
/** /**
* Change the server volume. * Change the server volume.
* @param {Discord.Message} message * @param {Discord.Message} message
* @param {number} percent * @param {number} percent
* @returns {boolean} Whether it succeed or not
* @example * @example
* client.player.setVolume(message, 90); * client.player.setVolume(message, 90);
*/ */
setVolume (message, percent) { setVolume (message, percent) {
// Get guild queue // Get guild queue
const queue = this.queues.get(message.guild.id) const queue = this.queues.get(message.guild.id)
if (!queue) return this.emit('error', 'NotPlaying', message) if (!queue) {
this.emit('error', 'NotPlaying', message)
return false
}
if (!queue.voiceConnection || !queue.voiceConnection.dispatcher) {
this.emit('error', 'MusicStarting', message)
return false
}
// Update volume // Update volume
queue.volume = percent queue.volume = percent
queue.voiceConnection.dispatcher.setVolumeLogarithmic(queue.calculatedVolume / 200) queue.voiceConnection.dispatcher.setVolumeLogarithmic(queue.calculatedVolume / 200)
return true
} }
/** /**
@ -843,35 +889,48 @@ class Player extends EventEmitter {
/** /**
* Skips to the next song. * Skips to the next song.
* @param {Discord.Message} message * @param {Discord.Message} message
* @returns {Queue} * @returns {boolean} Whether it succeed or not
*/ */
skip (message) { skip (message) {
// Get guild queue // Get guild queue
const queue = this.queues.get(message.guild.id) const queue = this.queues.get(message.guild.id)
if (!queue) return this.emit('error', 'NotPlaying', message) if (!queue) {
const currentTrack = queue.playing this.emit('error', 'NotPlaying', message)
return false
}
if (!queue.voiceConnection || !queue.voiceConnection.dispatcher) {
this.emit('error', 'MusicStarting', message)
return false
}
// End the dispatcher // End the dispatcher
queue.voiceConnection.dispatcher.end() queue.voiceConnection.dispatcher.end()
queue.lastSkipped = true queue.lastSkipped = true
// Return the queue // Return the queue
return queue return true
} }
/** /**
* Play back the previous song. * Play back the previous song.
* @param {Discord.Message} message * @param {Discord.Message} message
* @returns {Queue} * @returns {boolean} Whether it succeed or not
*/ */
back (message) { back (message) {
// Get guild queue // Get guild queue
const queue = this.queues.get(message.guild.id) const queue = this.queues.get(message.guild.id)
if (!queue) return this.emit('error', 'NotPlaying', message) if (!queue) {
this.emit('error', 'NotPlaying', message)
return false
}
if (!queue.voiceConnection || !queue.voiceConnection.dispatcher) {
this.emit('error', 'MusicStarting', message)
return false
}
queue.tracks.splice(1, 0, queue.previousTracks.shift()) queue.tracks.splice(1, 0, queue.previousTracks.shift())
// End the dispatcher // End the dispatcher
queue.voiceConnection.dispatcher.end() queue.voiceConnection.dispatcher.end()
queue.lastSkipped = true queue.lastSkipped = true
// Return the queue // Return the queue
return queue return true
} }
/** /**