Fix leave cooldown (#275)

Co-authored-by: Androz <androz2091@gmail.com>
This commit is contained in:
AkumaKitty 2021-02-18 22:42:54 +01:00 committed by GitHub
parent c804bd671f
commit 32e76dc2a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,6 +10,7 @@ const Util = require('./Util')
const { EventEmitter } = require('events') const { EventEmitter } = require('events')
const Client = new soundcloud.Client() const Client = new soundcloud.Client()
const { VimeoExtractor, DiscordExtractor, FacebookExtractor, ReverbnationExtractor, XVideosExtractor } = require('./Extractors/Extractor') const { VimeoExtractor, DiscordExtractor, FacebookExtractor, ReverbnationExtractor, XVideosExtractor } = require('./Extractors/Extractor')
var timeout
/** /**
* @typedef Filters * @typedef Filters
@ -721,6 +722,7 @@ class Player extends EventEmitter {
* client.player.play(message, "Despacito", true); * client.player.play(message, "Despacito", true);
*/ */
async play (message, query, firstResult = false) { async play (message, query, firstResult = false) {
clearTimeout(timeout)
if (!query || typeof query !== 'string') throw new Error('Play function requires search query but received none!') if (!query || typeof query !== 'string') throw new Error('Play function requires search query but received none!')
// clean query // clean query
@ -1138,7 +1140,9 @@ class Player extends EventEmitter {
if (queue.tracks.length === 1 && !queue.repeatMode && !firstPlay) { if (queue.tracks.length === 1 && !queue.repeatMode && !firstPlay) {
// Leave the voice channel // Leave the voice channel
if (this.options.leaveOnEnd && !queue.stopped) { if (this.options.leaveOnEnd && !queue.stopped) {
setTimeout(() => { // Remove the guild from the guilds list
this.queues.delete(queue.guildID)
timeout = setTimeout(() => {
queue.voiceConnection.channel.leave() queue.voiceConnection.channel.leave()
}, this.options.leaveOnEndCooldown || 0) }, this.options.leaveOnEndCooldown || 0)
} }