-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
54 lines (46 loc) · 1.75 KB
/
bot.js
File metadata and controls
54 lines (46 loc) · 1.75 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
require('dotenv').config();
const Discord = require('discord.js');
const client = new Discord.Client();
const USER_ROLE = 'Watermelon';
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
checkIfWatermelonRoleExists(msg);
reactWithWatermelon(msg);
botReply(msg);
helpWatermelonFarmer(msg);
});
const helpWatermelonFarmer = (msg) => {
if(msg.content === '!help-watermelon-farmer') {
const role = msg.guild.roles.cache.find(x => x.name === USER_ROLE);
msg.member.roles.add(role);
msg.reply("Thanks for helping me out! Now whenever you type 'watermelon' in a message I'll share my harvest with you. 🍉")
}
};
const reactWithWatermelon = (msg) => {
const isWatermelonRole = msg.member.roles.cache.map(x => x.name).indexOf(USER_ROLE) > -1;
if (isWatermelonRole && msg.content.toLowerCase().indexOf("watermelon") > -1) {
msg.react('🍉');
}
};
const botReply = (msg) => {
if(msg.mentions.members.map(x => x.user.username).indexOf("Watermelon Farmer") > -1) {
msg.reply("looks like you asked for me, but I'm a little busy right now. I can use your help though! Message '!help-watermelon-farmer' to help me harvest watermelons.")
}
};
const checkIfWatermelonRoleExists = (msg) => {
const role = msg.guild.roles.cache.find(x => x.name === USER_ROLE);
if (role === undefined) {
msg.guild.roles.create({
data:{
name:"Watermelon",
color:"GREEN",
},
reason:"For people that like watermelon.",
})
.then(role => console.log(`Created new role with name ${role.name}`))
.catch(console.error); //Handle an error
}
}
client.login(process.env.BOT_TOKEN);