-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
135 lines (116 loc) · 3.61 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
require("dotenv").config();
// Tyto věci lze měnit
const prefix = "!";
const guild_id = "842524673055916063";
const verified_role_id = "856866661863522334";
const fs = require("fs");
const Discord = require("discord.js");
const client = new Discord.Client();
let roleName = "Ověřeno";
client.on("ready", async () => {
console.log(`Bot načten ${client.user.tag}!`);
await client.user.setActivity("si s ověřením #verification");
roleName = client.guilds.get(guild_id).roles.get(verified_role_id).name;
});
client.on("message", msg => {
const args = msg.content
.slice(prefix.length)
.trim()
.split(/ +/g);
const command = args
.shift()
.toLowerCase()
.replace("/", "");
// cmd verifymsg = vytvoří embed
if (
!msg.author.bot &&
msg.content.indexOf(prefix) === 0 &&
command === "verifymsg"
) {
// Pokud odesílatel zprávy není vlastníkem guild, zruší akci
if (msg.member.guild.ownerID !== msg.member.id) return;
const introMessageContent = fs.readFileSync("intro-message.md", {
encoding: "utf8",
flag: "r"
});
const communityGuidelinesContent = fs.readFileSync(
"community-guidelines.md",
{ encoding: "utf8", flag: "r" }
);
const verificationMessageContent = fs.readFileSync(
"verification-message.md",
{ encoding: "utf8", flag: "r" }
);
const embed = new Discord.RichEmbed();
const welcomeTitle = `Vítej na ${msg.guild.name}!`;
embed.setColor('RANDOM')
embed.addField(welcomeTitle, introMessageContent);
embed.addField("🎗 Zásady komunity", communityGuidelinesContent);
embed.addField("🔐 Získání ověření", verificationMessageContent);
msg.channel
.send({ embed })
.then(theVerificationMessage => theVerificationMessage.react("857025231817015306"));
msg.delete();
}
return;
});
client.on("messageReactionAdd", ({ message: { channel } }, user) => {
if (/verification/.test(channel.name)) {
channel.guild
.fetchMember(user)
.then(member => {
return member.addRole(verified_role_id);
})
.then(() => {
console.log(
`Role ${roleName} byla úspěšně přidělena uživateli ${user.tag}!`
);
})
.catch(error => {
console.error(error);
});
}
});
client.on("messageReactionRemove", ({ message: { channel } }, user) => {
if (/verification/.test(channel.name)) {
channel.guild
.fetchMember(user)
.then(member => {
return member.removeRoles(verified_role_id);
})
.then(() => {
console.log(
`Role ${roleName} byla úspěšně odebrána uživateli ${user.tag}!`
);
})
.catch(error => {
console.error(error);
});
}
});
client.on("raw", ({ d: data, t: event }) => {
if (["MESSAGE_REACTION_ADD", "MESSAGE_REACTION_REMOVE"].includes(event)) {
const { channel_id, user_id, message_id, emoji } = data;
const channel = client.channels.get(channel_id);
if (!channel.messages.has(message_id))
channel.fetchMessage(message_id).then(message => {
const reaction = message.reactions.get(
emoji.id ? `${emoji.name}:${emoji.id}` : emoji.name
);
const user = client.users.get(user_id);
if (reaction) reaction.users.set(user_id, user);
return client.emit(
event === "MESSAGE_REACTION_ADD"
? "messageReactionAdd"
: "messageReactionRemove",
reaction,
user
);
});
}
});
if (process.env.TOKEN !== null) {
client.login(process.env.TOKEN);
} else {
console.error("Bot token je prázdný!");
}