nyx/unused/events/messageReaction.js

31 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-09-21 01:51:56 +02:00
const client = require("../../bot");
2021-09-06 12:38:25 +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`);
});
2021-09-06 12:38:25 +02:00
});
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;
2021-09-06 12:38:25 +02:00
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`);
});
2021-09-06 12:38:25 +02:00
});