Add leaveOnEndCooldown option

Closes #72
This commit is contained in:
Androz2091 2020-12-27 00:15:49 +01:00
parent 7416662b1b
commit a2f2057d6a
2 changed files with 8 additions and 3 deletions

View file

@ -56,6 +56,7 @@ const filters = {
/**
* @typedef PlayerOptions
* @property {boolean} [leaveOnEnd=true] Whether the bot should leave the current voice channel when the queue ends.
* @property {number} [leaveOnEndCooldown=0] Used when leaveOnEnd is enabled, to let the time to users to add new tracks.
* @property {boolean} [leaveOnStop=true] Whether the bot should leave the current voice channel when the stop() function is used.
* @property {boolean} [leaveOnEmpty=true] Whether the bot should leave the voice channel if there is no more member in it.
* @property {number} [leaveOnEmptyCooldown=0] Used when leaveOnEmpty is enabled, to let the time to users to come back in the voice channel.
@ -717,9 +718,12 @@ class Player extends EventEmitter {
// If there isn't next music in the queue
if (queue.tracks.length === 1 && !queue.repeatMode && !firstPlay) {
// Leave the voice channel
if (this.options.leaveOnEnd && !queue.stopped) queue.voiceConnection.channel.leave()
// Remove the guild from the guilds list
this.queues.delete(queue.guildID)
if (this.options.leaveOnEnd && !queue.stopped) {
setTimeout(() => {
queue.voiceConnection.channel.leave()
// Remove the guild from the guilds list
this.queues.delete(queue.guildID)
}, this.options.leaveOnEndCooldown || 0)
// Emit stop event
if (queue.stopped) {
return this.emit('musicStop')

1
typings/index.d.ts vendored
View file

@ -47,6 +47,7 @@ declare module 'discord-player' {
}
interface PlayerOptions {
leaveOnEnd: boolean;
leaveOnEndCooldown?: number;
leaveOnStop: boolean;
leaveOnEmpty: boolean;
leaveOnEmptyCooldown?: number;