Pause music when everyone leaves the voice channel, try a slightly different approach to voice events

This commit is contained in:
Essem 2021-09-13 17:24:15 -05:00
parent 95dc02aed5
commit c59a0bf0c4
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
5 changed files with 366 additions and 363 deletions

View file

@ -7,10 +7,12 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
const connection = players.get(oldChannel.guild.id);
if (connection && connection.type === "music" && oldChannel.id === connection.voiceChannel.id) {
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id).length === 0) {
connection.player.pause(true);
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return...");
const awaitRejoin = new AwaitRejoin(oldChannel, true);
awaitRejoin.on("end", (rejoined, member) => {
if (rejoined) {
connection.player.pause(false);
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: member.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel });
waitMessage.edit(`🔊 ${member.mention} is the new voice channel host.`);
} else {