Skip to content

Commit

Permalink
update givereactrole
Browse files Browse the repository at this point in the history
  • Loading branch information
Bigbugman committed Sep 19, 2023
1 parent b23d9ce commit 9267c68
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions events/givereactrole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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],
});
Expand All @@ -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);
Expand All @@ -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({
Expand Down

0 comments on commit 9267c68

Please sign in to comment.