-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
71 lines (52 loc) · 1.96 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
let Discord = require('discord.js')
let Client = new Discord.Client()
let dotenv = require('dotenv');
// Grabs the BOT_TOKEN from .env and stores in on the `process.env`
dotenv.load()
let allowedRoles = process.env.ALLOWED_ROLES.split(',')
let botToken = process.env.BOT_TOKEN
// allowed strings
let allowedString = ''
allowedRoles.forEach((role) => {
allowedString = allowedString.concat('- ' + role + '\n')
})
Client.on('message', msg => {
// Set prefix
let prefix = "!"
if (!msg.content.startsWith(prefix)
|| msg.author.bot
) return
if (msg.content.startsWith(prefix + 'role')) {
// Get args
let args = msg.content.split(" ");
if (args.length < 2 || args[1] == '--help') {
msg.channel.sendMessage('These are the roles you\'re allowed to join: \n'+
allowedString +
'\nuse "!role `<role_name>` to join a role')
return
}
// Get the role
let role = msg.guild.roles.find("name", args[1].toLowerCase());
if (!role || role === null) {
msg.channel.sendMessage('Could not find a role by that name.')
return
}
if (allowedRoles.indexOf(role.name) === -1) {
msg.channel.sendMessage('Doesn\'t look like you\'re allowed to join that group. \nFor a list of allowed roles type `!role --help`')
return
}
msg.member.addRole(role).catch(console.error);
msg.channel.sendMessage('You\'ve been added to: ' + role.name)
return
}
})
Client.on("guildMemberAdd", member => {
console.log(`New User "${member.user.username}" has joined "${member.guild.name}"` );
//member.guild.defaultChannel.sendMessage(`Welcome "${member.user.username}"! Be sure to set your platform by typing "!role"`);
})
Client.on('ready', () => {
Client.user.setGame('type !role --help')
console.log(`Ready to set roles in ${Client.channels.size} channels on ${Client.guilds.size} servers, for a total of ${Client.users.size} users.`)
})
Client.on('error', e => { console.error(e) })
Client.login(botToken)