Skip to content

Commit 02b80b0

Browse files
authored
Added Leadership detect +
Added Leadership detection and cleaned up the if statements when a member responds to the #rules chat
1 parent 1af54ec commit 02b80b0

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ const handleMessage = (msg) => {
2424
const msgs = msg.content.split(" ");
2525
const tonyCommands = TonyCommands(msg);
2626
const roboCommands = RoboCommands(msg);
27-
let role = msg.member.guild.roles.find('name', 'Leadership');
27+
let Leadrole = msg.member.guild.roles.find('name', 'Leadership');
2828

2929
//todo: check for leadership priviliges
3030
// leadership commands
31-
if ((msgs[0] === PREFIX && msgs[1] === TonyKey)&&(role.id === msg.member.guild.roles.find('name','Leadership').id)) {
31+
if ((msgs[0] === PREFIX && msgs[1] === TonyKey) && (msg.member.roles.has(Leadrole.id))) {
3232
// cutting prefixes
3333
msgs.splice(0, 2);
3434
if (msgs.length === 0 || msgs === undefined) {
3535
msg.reply('At least one argument is need to complete a command.');
3636
} else {
3737
// ternary check for tony commands in map.
38-
(tonyCommands[msgs.join(" ")]) ? tonyCommands[msgs.join(" ")](): msg.reply('The command you entered is could not be found.');
38+
(tonyCommands[msgs.join(" ")]) ? tonyCommands[msgs.join(" ")]() : msg.reply('The command you entered is could not be found.');
3939
}
4040
} else if (msgs[0] === PREFIX) {
4141
// non leadership commands
@@ -45,14 +45,15 @@ const handleMessage = (msg) => {
4545
msg.reply('At least one argument is need to complete a command.');
4646
} else {
4747
// ternary check for function in robocommands map
48-
(roboCommands[msgs.join(" ")]) ? roboCommands[msgs.join(" ")](): msg.reply('The command you entered is could not be found.');
48+
(roboCommands[msgs.join(" ")]) ? roboCommands[msgs.join(" ")]() : msg.reply('The command you entered is could not be found.');
4949
}
5050
}
5151

5252
}
5353

5454
bot.on('ready', () => console.log('Robo is on.'));
5555

56+
// When a new member joins the Discord
5657
bot.on('guildMemberAdd', member => {
5758
const channel = member.guild.channels.find(ch => ch.name === 'welcome');
5859
if (!channel) return;
@@ -62,13 +63,18 @@ bot.on('guildMemberAdd', member => {
6263
channel.send(`Welcome to the server, ${member} be sure to read #rules 👋`);
6364
});
6465

66+
// When a new member finishes reading the rules
6567
bot.on('message', message => {
68+
let Unrole = message.member.guild.roles.find('name', 'Unapproved');
6669
if (message.channel.name == 'rules') {
67-
let role = message.member.guild.roles.find('name', 'Unapproved');
68-
message.member.removeRole(role);
70+
if (message.content === 'READ') {
71+
if (message.member.roles.has(Unrole.id)) {
72+
message.member.removeRole(Unrole);
73+
}
74+
}
6975
message.delete(0)
70-
.then(msg => console.log(`Deleted message from ${msg.author.username}`))
71-
.catch(console.error);
76+
.then(msg => console.log(`Deleted message from ${msg.author.username}`))
77+
.catch(console.error);
7278
}
7379
});
7480

0 commit comments

Comments
 (0)