nyx/events/reactionroles.js
night0721 bc346138dd Bot
2021-06-12 18:53:51 +08:00

30 lines
1.2 KiB
JavaScript

const client = require("../index");
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`);
});
});