-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
66 lines (55 loc) · 1.68 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
require("dotenv").config();
const DiscordClient = require("./lib/discordClient");
const welcomeMsg = require("./utils/welcomeMsg");
const client = new DiscordClient(process.env.BOT_TOKEN);
client.onReady(() => {
console.log(`Logged in ${client.client.user.username}`);
});
client.addChannelListener("quest-completions", async (msg) => {
try {
const { content, author } = msg;
if (content !== "!complete quest1") {
// delete message from user
msg.delete();
// dm user telling them the format is wrong
client.sendDirectMessage(
author,
"You sent the wrong format `" +
content +
"`, to complete a quest send `!complete quest1`"
);
}
} catch (e) {
console.log(`Error: ${e.message}`);
}
});
client.addEventListener("messageReactionAdd", async (msgReaction, user) => {
try {
const {
message: {
channel: { name: channelName, guild },
content: messageContent,
author,
},
} = msgReaction;
if (
channelName === "quest-completions" &&
messageContent == "!complete quest1"
) {
if (guild.available) {
const member = await guild.member(user);
const memberRoles = member.roles.cache.map((role) => role.name);
if (memberRoles.includes("Diamond Founder")) {
const { id: roleId } = guild.roles.cache.find(
(role) => role.name === "MetaGame Player"
);
const messageAuthor = await guild.member(author);
await messageAuthor.roles.add([roleId]);
client.sendDirectMessage(author, welcomeMsg);
}
}
}
} catch (e) {
console.log(`Error: ${e.message}`);
}
});