From 9267c689a7c34d5dd2faa495152c71713a78b691 Mon Sep 17 00:00:00 2001 From: zhitao Date: Tue, 19 Sep 2023 23:12:54 +1000 Subject: [PATCH] update givereactrole --- events/givereactrole.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/events/givereactrole.ts b/events/givereactrole.ts index e0022a51..47a8e1d2 100644 --- a/events/givereactrole.ts +++ b/events/givereactrole.ts @@ -5,7 +5,7 @@ export default { once: false, async execute(reaction:any, user:any) { if (user.bot) return; - + console.log(user); if (reaction.partial) { try { await reaction.fetch(); @@ -24,27 +24,31 @@ export default { const roleId = data[0].role_id; const senderId = await reactRoles.get_sender(messageId); + console.log(senderId); + console.log(user.id); // Check if emoji is ⛔ and if the user is the sender - if (reaction.emoji.name === "⛔" && user.id === senderId) return; + if (reaction.emoji.name === "⛔" && user.id !== senderId) return; // Check if message has ⛔ reacted by the sender - // If not, assign the role to the user + // If not assign the role to the user const reactions = reaction.message.reactions; - const noEntryReact = reactions.cache.find((r:any )=> r.emoji.name === "⛔"); + const noEntryReact = reactions.resolve("⛔"); if (noEntryReact) { noEntryReact.users.fetch().then(async (userList:any) => { - if (userList.has(senderId)) { - reactions.cache.find((r:any) => r.emoji === reaction.emoji).users.remove(user); + if (!userList.has(senderId)) { + reactions.resolve(reaction).users.remove(user); + const botName = await reaction.message.author.username; // Notify user that role was not assigned const notification = new EmbedBuilder() .setColor("#7cd699") .setTitle("Role could not be assigned") - .setAuthor(botName) - .setDescription(`You can no longer react to the message in "${reaction.message.guild.name}" to get a role`); - + .setAuthor({ name: botName, iconURL: "https://avatars.githubusercontent.com/u/164179?s=200&v=4" }) + .setDescription( + `You can no longer react to the message in "${reaction.message.guild.name}" to get a role`, + ); user.send({ embeds: [notification], }); @@ -57,7 +61,6 @@ export default { } }, }; - async function giveRole(reaction:any, user:any, roleId:any) { try { reaction.message.guild.members.cache.get(user.id).roles.add(roleId); @@ -70,7 +73,7 @@ async function giveRole(reaction:any, user:any, roleId:any) { const notification = new EmbedBuilder() .setColor("#7cd699") .setTitle("Roles updated!") - .setAuthor({ name: botName}) + .setAuthor({ name: botName, iconURL: "https://avatars.githubusercontent.com/u/164179?s=200&v=4" }) .setDescription(`You reacted to a message in "${reaction.message.guild.name}" and were assigned the "${roleName}" role`); user.send({