2021-06-24 09:53:19 +02:00
|
|
|
const client = require("../bot");
|
2021-06-12 12:53:51 +02:00
|
|
|
const Schema = require("../models/reaction");
|
|
|
|
|
|
|
|
client.on("messageReactionAdd", async (reaction, user) => {
|
|
|
|
if (reaction.message.partial) await reaction.message.fetch();
|
|
|
|
if (reaction.partial) await reaction.fetch();
|
|
|
|
if (user.bot) return;
|
|
|
|
if (!reaction.message.guild) return;
|
|
|
|
Schema.findOne({ Message: reaction.message.id }, async (err, data) => {
|
|
|
|
if (!data) return;
|
|
|
|
if (!Object.keys(data.Roles).includes(reaction.emoji.name)) return;
|
|
|
|
const [roleid] = data.Roles[reaction.emoji.name];
|
|
|
|
reaction.message.guild.members.cache.get(user.id).roles.add(roleid);
|
|
|
|
user.send(`A role has been added`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
client.on("messageReactionRemove", async (reaction, user) => {
|
|
|
|
if (reaction.message.partial) await reaction.message.fetch();
|
|
|
|
if (reaction.partial) await reaction.fetch();
|
|
|
|
if (user.bot) return;
|
|
|
|
if (!reaction.message.guild) return;
|
|
|
|
Schema.findOne({ Message: reaction.message.id }, async (err, data) => {
|
|
|
|
if (!data) return;
|
|
|
|
if (!Object.keys(data.Roles).includes(reaction.emoji.name)) return;
|
|
|
|
|
|
|
|
const [roleid] = data.Roles[reaction.emoji.name];
|
|
|
|
reaction.message.guild.members.cache.get(user.id).roles.remove(roleid);
|
|
|
|
user.send(`A role has been removed`);
|
|
|
|
});
|
|
|
|
});
|