forked from appujet/lavamusic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
voiceStateUpdate.js
68 lines (58 loc) · 2.3 KB
/
voiceStateUpdate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const { MessageEmbed } = require("discord.js");
const delay = require("delay");
module.exports = async (client, oldState, newState) => {
const channel = newState.guild.channels.cache.get(
newState.channel?.id ?? newState.channelId
)
// Only keep the bot in the voice channel by its self for 3 minutes
const player = client.manager?.players.get(newState.guild.id)
if (!player) return
if (!newState.guild.members.cache.get(client.user.id).voice.channelId) player.destroy()
// Check for stage channel audience change
if (newState.id == client.user.id && channel?.type == 'GUILD_STAGE_VOICE') {
if (!oldState.channelId) {
try {
await newState.guild.me.voice.setSuppressed(false).then(() => console.log(null))
} catch (err) {
player.pause(true)
}
} else if (oldState.suppress !== newState.suppress) {
player.pause(newState.suppress)
}
}
if (oldState.id === client.user.id) return
if (!oldState.guild.members.cache.get(client.user.id).voice.channelId) return
// Don't leave channel if 24/7 mode is active
if (player.twentyFourSeven) return
// Make sure the bot is in the voice channel that 'activated' the event
if (oldState.guild.members.cache.get(client.user.id).voice.channelId === oldState.channelId) {
if (
oldState.guild.me.voice?.channel &&
oldState.guild.me.voice.channel.members.filter((m) => !m.user.bot).size === 0
) {
const vcName = oldState.guild.me.voice.channel.name
await delay(180000)
// times up check if bot is still by themselves in VC (exluding bots)
const vcMembers = oldState.guild.me.voice.channel?.members.size
if (!vcMembers || vcMembers === 1) {
const newPlayer = client.manager?.players.get(newState.guild.id)
newPlayer ? player.destroy() : oldState.guild.me.voice.channel.leave()
const embed = new MessageEmbed(client, newState.guild)
// eslint-disable-next-line no-inline-comments
.setDescription(
`I left 🔉 **${vcName}** because I was inactive for too long.`
)
try {
const c = client.channels.cache.get(player.textChannel)
if (c)
c.send({ embeds: [embed] }).then((m) =>
setTimeout(() =>
m.delete(), 30000)
)
} catch (err) {
client.logger.error(err.message)
}
}
}
}
};