This repository has been archived by the owner on Jan 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
voicebot.js
74 lines (60 loc) · 2.66 KB
/
voicebot.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
69
70
71
72
73
74
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require('./config.json');
const RequestChannelId = config.requestChannelId; //보이스 채널 신청 채널
const ParentChannelId = config.parentChannelId; //보이스 채널 생성 위치
const LogChannelId = config.logChannelId; //유저 JOIN, LEAVE 기록할 채널
const GameRunningRole = config.gameRunningRole; //게임 실행시 부여될 등급
const GameTitleName = config.gameTitleName; //게임 이름
const UserChannels = [];
const GameUserList = [];
client.on('ready', () => {
});
client.on("voiceStateUpdate", (oldMember, newMember) => {
let userChannelIndex = UserChannels.findIndex(id => id === oldMember.channelID);
if (newMember.channelID === RequestChannelId) {
newMember.guild.channels.create(newMember.member.user.tag, {
type: "voice",
bitrate: config.bitrate,
parent: newMember.guild.channels.cache.find(channel => channel.id === ParentChannelId)
}).then(r => {
r.createOverwrite(newMember.member, {
'MANAGE_CHANNELS': true
}).catch(console.error);
newMember.member.voice.setChannel(r.id);
UserChannels.push(r.id);
});
}
if (userChannelIndex !== -1) {
if (oldMember.channel.members.size <= 0) {
oldMember.channel.delete("user empty").then(channel => {
UserChannels.slice(userChannelIndex, 1);
});
}
}
});
client.on("presenceUpdate", (oldUser, newUser) => {
let gamingUser = GameUserList.findIndex(id => id === newUser.user.id);
if (gamingUser === -1) {
if (newUser.activities.findIndex(activity => activity.name.toLowerCase() === GameTitleName.toLowerCase()) !== -1) {
newUser.member.roles.add(newUser.guild.roles.cache.get(GameRunningRole)).then(role => {
GameUserList.push(newUser.user.id);
});
}
} else {
if (oldUser.activities.findIndex(activity => activity.name.toLowerCase() === GameTitleName.toLowerCase()) !== -1) {
oldUser.member.roles.remove(oldUser.guild.roles.cache.get(GameRunningRole)).then(role => {
GameUserList.slice(GameUserList.findIndex(id => id === newUser.user.id), 1);
});
}
}
});
client.on('guildMemberAdd', member => {
console.log("입장");
client.channels.cache.get(LogChannelId).send(`${member.user.tag} 님이 입장`);
});
client.on("guildMemberRemove", member => {
console.log("퇴장");
client.channels.cache.get(LogChannelId).send(`${member.user.tag} 님이 퇴장`);
});
client.login(config.token);