commit
f3a101e894
1 changed files with 26 additions and 13 deletions
|
@ -76,8 +76,17 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
const queue = this.getQueue(oldState.guild.id);
|
const queue = this.getQueue(oldState.guild.id);
|
||||||
if (!queue) return;
|
if (!queue) return;
|
||||||
|
|
||||||
if (oldState.channelId && newState.channelId && oldState.channelId !== newState.channelId && newState.member.id === newState.guild.me.id) {
|
if (oldState.channelId && newState.channelId && oldState.channelId !== newState.channelId) {
|
||||||
if (queue?.connection) queue.connection.channel = newState.channel;
|
if (queue?.connection && newState.member.id === newState.guild.me.id) queue.connection.channel = newState.channel;
|
||||||
|
if (newState.member.id === newState.guild.me.id || newState.member.id !== newState.guild.me.id && oldState.channelId === queue.connection.channel.id) {
|
||||||
|
if (!Util.isVoiceEmpty(queue.connection.channel)) return;
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
if (!Util.isVoiceEmpty(queue.connection.channel)) return;
|
||||||
|
if (!this.queues.has(queue.guild.id)) return;
|
||||||
|
if (queue.options.leaveOnEmpty) queue.destroy();
|
||||||
|
this.emit("channelEmpty", queue);
|
||||||
|
}, queue.options.leaveOnEmptyCooldown || 0).unref();
|
||||||
|
queue._cooldownsTimeout.set(`empty_${oldState.guild.id}`, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!oldState.channelId && newState.channelId && newState.member.id === newState.guild.me.id) {
|
if (!oldState.channelId && newState.channelId && newState.member.id === newState.guild.me.id) {
|
||||||
|
@ -109,11 +118,14 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
const emptyTimeout = queue._cooldownsTimeout.get(`empty_${oldState.guild.id}`);
|
const emptyTimeout = queue._cooldownsTimeout.get(`empty_${oldState.guild.id}`);
|
||||||
const channelEmpty = Util.isVoiceEmpty(queue.connection.channel);
|
const channelEmpty = Util.isVoiceEmpty(queue.connection.channel);
|
||||||
|
|
||||||
|
if (newState.channelId === queue.connection.channel.id) {
|
||||||
if (!channelEmpty && emptyTimeout) {
|
if (!channelEmpty && emptyTimeout) {
|
||||||
clearTimeout(emptyTimeout);
|
clearTimeout(emptyTimeout);
|
||||||
queue._cooldownsTimeout.delete(`empty_${oldState.guild.id}`);
|
queue._cooldownsTimeout.delete(`empty_${oldState.guild.id}`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (oldState.channelId === queue.connection.channel.id) {
|
||||||
if (!Util.isVoiceEmpty(queue.connection.channel)) return;
|
if (!Util.isVoiceEmpty(queue.connection.channel)) return;
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
if (!Util.isVoiceEmpty(queue.connection.channel)) return;
|
if (!Util.isVoiceEmpty(queue.connection.channel)) return;
|
||||||
|
@ -124,6 +136,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
queue._cooldownsTimeout.set(`empty_${oldState.guild.id}`, timeout);
|
queue._cooldownsTimeout.set(`empty_${oldState.guild.id}`, timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a queue for a guild if not available, else returns existing queue
|
* Creates a queue for a guild if not available, else returns existing queue
|
||||||
|
|
Loading…
Reference in a new issue