-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
80 lines (62 loc) · 2.17 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const Discord = require('discord.js');
const client = new Discord.Client();
const roles = require('./roles.json');
const config = require('./config.json');
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
// Ignore everything that doesn't start with !
if (!message.content.startsWith("!")) return false;
if (!config.channel.includes(message.channel.name)) return false;
// Setup command, creates all roles from config
// Also checks if roles already exist and skips those
if (message.content.includes('setup')) {
if (message.member.permissions.has('ADMINISTRATOR')) {
let roleArr = Object.keys(roles);
roleArr.forEach(function (role) {
if (message.guild.roles.find("name", role) != null) return false;
message.guild.createRole({
name: role,
color: roles[role]
}).catch(console.error)
})
if (message.guild.roles.find("name", "Ready for Match") != null) return false;
message.guild.createRole({
name: "Ready for Match",
hoist: true,
mentionable: true
}).catch(console.error)
} else {
message.reply('insufficient permissions')
}
}
if (message.content.includes('ready')) {
let rdyRole = message.guild.roles.find("name", "Ready for Match")
if (rdyRole !== null) {
if (message.member.roles.find("name", "Ready for Match")) {
message.member.removeRole(rdyRole)
} else {
message.member.addRole(rdyRole)
}
}
}
// Actual role part
// First we match for everything that follows after a !
let match = /!([a-zA-Z0-9_ ]*)/g.exec(message.content)
if (match && Object.keys(roles).includes(match[1])) {
// If it's matched, let's check if a role with this name exists
let role = message.guild.roles.find("name", match[1])
if (role !== null) {
if (message.member.roles.find("name", match[1])) {
// If our user already has this role, remove it
message.member.removeRole(role)
} else {
// If our user doesn't have this role, add it
message.member.addRole(role)
}
}
}
});
// Log our bot in
client.login(config.token);