-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
89 lines (76 loc) · 3.05 KB
/
Copy pathindex.js
File metadata and controls
89 lines (76 loc) · 3.05 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Copyright 2023 WideBot
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const Discord = require('discord.js');
const YAML = require('yaml');
const fs = require('fs');
let config = {};
try {
config = YAML.parse(fs.readFileSync("./config.yml", "utf-8"), { prettyErrors: true })
} catch (err) {
console.error(err);
}
client = new Discord.Client({
intents: Object.keys(Discord.Intents.FLAGS).map(x => Discord.Intents.FLAGS[x])
});
client.on('ready', () => {
console.log(`Bot connected as ${client.user.tag}!`);
updateMemberCount();
setInterval(updateMemberCount, 5 * 60 * 1000);
});
async function updateMemberCount() {
const guild = client.guilds.cache.get(config.Server_ID);
if (!guild) {
console.warn(`The server with ID "${config.Server_ID}" was not found. Make sure the ID is correct.`);
return;
}
const memberCount = guild.memberCount;
const botCount = guild.members.cache.filter(member => member.user.bot).size;
const userCount = memberCount - botCount;
if (config.Status.Member.Enabled) {
const member_channel = guild.channels.cache.get(config.Status.Member.Channel_ID);
if (!member_channel) {
console.warn(`The channel with ID "${config.Status.Member.Channel_ID}" was not found. Make sure the ID is correct.`);
return;
} else {
const memberChannelName = `${config.Status.Member.Channel_Name}${memberCount}`;
if (member_channel.name != memberChannelName) {
await member_channel.setName(memberChannelName);
}
}
}
if (config.Status.Bot.Enabled) {
const bot_channel = guild.channels.cache.get(config.Status.Bot.Channel_ID);
if (!bot_channel) {
console.warn(`The channel with ID "${config.Status.Bot.Channel_ID}" was not found. Make sure the ID is correct.`);
return;
} else {
const botChannelName = `${config.Status.Bot.Channel_Name}${botCount}`;
if (bot_channel.name != botChannelName) {
await bot_channel.setName(botChannelName);
}
}
}
if (config.Status.User.Enabled) {
const user_channel = guild.channels.cache.get(config.Status.User.Channel_ID);
if (!user_channel) {
console.warn(`The channel with ID "${config.Status.User.Channel_ID}" was not found. Make sure the ID is correct.`);
return;
} else {
const userChannelName = `${config.Status.User.Channel_Name}${userCount}`;
if (user_channel.name != userChannelName) {
await user_channel.setName(userChannelName);
}
}
}
}
client.login(config.Token);