-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
64 lines (55 loc) · 1.69 KB
/
index.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
const DiscordApp = require("discord.js")
const client = new DiscordApp.Client()
// Whitelist channel to prevent channel being deleted
// The first array is Creator Channel ( Click to Join )
var WhitelistedChannels = ["###CLICK TO JOIN###", "### WHITELISTED CHANNEL ###"]
function ChannelLeave(member, channel) {
let userCount = GetChannelUserCount(channel)
if (userCount == 0 && channel) {
if (CreatorChannels.indexOf(channel.id) < 0) {
channel.delete()
}
}
}
function ChannelJoin(member, channel) {
if (CreatorChannels.indexOf(channel.id) == 0) {
CreateAutoChannel(member, channel)
}
}
function GetChannelUserCount(channel) {
if (channel) {
return channel.members.reduce((acc, member) => acc + 1, 0)
}
return 0
}
function CreateAutoChannel(member, channel) {
console.log("Creating Channel")
channel.clone({
name: `${member.displayName}'s Channel`
})
.then(newChannel => {
member.voice.setChannel(newChannel)
newChannel.overwritePermissions(
[
{
id: member.id,
allow: ['MANAGE_CHANNELS']
}
]
)
})
}
client.on("voiceStateUpdate", (oldState, newState) => {
if (oldState && newState) {
if (oldState.channelID === newState.channelID) {
return
}
}
if (oldState && oldState.channelID) {
ChannelLeave(oldState.member, oldState.guild.channels.resolve(oldState.channelID))
}
if (newState && newState.channelID) {
ChannelJoin(newState.member, newState.guild.channels.resolve(newState.channelID))
}
})
client.login(process.env.BOT_TOKEN)