-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (37 loc) · 1.51 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
const Discord = require("discord.js")
const client = new Discord.Client();
const config = require("./config.json")
client.login(config.token);
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}`);
})
client.on('message', message => {
if (message.channel.id !== config.channel) { return; }
message.react(config.emoji)
})
client.on("raw", async event => {
// Reaction set and reaction set inside guild
if (event.t !== "MESSAGE_REACTION_ADD" ||
!event.d.guild_id) { return; }
// reaction wasn't set by this bot, was set inside required channel and with correct emoji
if (event.d.member.user.id === client.user.id ||
event.d.channel_id !== config.channel ||
event.d.emoji.name !== config.emoji) { return; }
let ch = await client.channels.fetch(config.channel)
let m = await ch.messages.fetch(event.d.message_id);
let react = new Discord.MessageReaction(client, event.d, m);
// remove reaction of user without required role
if (!event.d.member.roles.includes(config.role)) {
return await react.users.remove(event.d.member.user.id)
} else {
let r = m.reactions.cache.find(r => r.emoji.name === config.emoji)
if (r.count >= config.count + 1) { m.member.roles.add(config.role) }
}
})
client.on("guildMemberAdd", async m => {
let re = /.*(plum).*/gmi
if (m.user.username.match(re)) {
ch = await client.channels.fetch(config.pipis)
ch.send(`User <@${m.user.id}> joined your guild.`)
}
})