-
Notifications
You must be signed in to change notification settings - Fork 1
/
roleSync.js
78 lines (61 loc) · 2.79 KB
/
roleSync.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
75
76
77
78
// const { Client, GatewayIntentBits } = require(`discord.js`);
// const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent] });
// const token = 'MTE0NDgzNTcyNTk2NDA5NTU0OA.GyCHgs.BqRWIUcdk5SlILh-uxRgB_4bC95mfscSkG8z4Y'; // Discord bot token
// const hostServerId = "1144864344803389501"; // Server to copy roles from
// const followerServerId = "1144835324502089758"; // Server to copy roles to
// client.on('ready', () => {
// console.log(`Logged in as ${client.user.tag}!`);
// syncRoles();
// });
// client.on('guildMemberUpdate', () => {
// syncRoles();
// });
// async function syncRoles() {
// const hostServer = client.guilds.cache.get(hostServerId);
// const followerServer = client.guilds.cache.get(followerServerId);
// const hostList = createHostRoleList(hostServer);
// await createMissingRoles(hostServer, followerServer);
// followerServer.members.cache.forEach(async (member) => {
// const rolesToAdd = hostList[member.id];
// if (rolesToAdd) {
// await synchronizeRoles(member, followerServer, rolesToAdd);
// }
// });
// }
// function createHostRoleList(server) {
// const hostList = {};
// server.members.cache.forEach((member) => {
// hostList[member.id] = member.roles.cache.map((role) => role.name);
// });
// return hostList;
// }
// async function createMissingRoles(hostServer, followerServer) {
// const followerRoleNames = followerServer.roles.cache.map(role => role.name);
// for (const role of hostServer.roles.cache.values()) {
// if (!followerRoleNames.includes(role.name) && role.name !== "@everyone") {
// await followerServer.roles.create({
// name: role.name,
// color: role.color
// });
// console.log("Creating " + role.name);
// }
// }
// }
// async function synchronizeRoles(member, followerServer, rolesToAdd) {
// const rolesToRemove = member.roles.cache.filter(role => !rolesToAdd.includes(role.name) && role.name !== "@everyone");
// rolesToRemove.filter((role)=>{return role!=null})
// for (const role of rolesToRemove.values()) {
// await member.roles.remove(role);
// console.log("Removing " + role.name);
// }
// try {
// for (const roleName of rolesToAdd) {
// const role = followerServer.roles.cache.find(role => role.name === roleName);
// if (role) {
// await member.roles.add(role);
// }
// }
// } catch (error) {
// }
// }
// client.login(token);