0
client.on('messageReactionAdd', async (reaction, user) => {
  const role = guild.roles.cache.find((role) => role.name === 'specific role')

  if (reaction.emoji.id == '759643335043448834' && reaction.author.roles.has(role.id))
  return
  else await reaction.message.delete({timeout:2500})
  
});

so right now this is giving me a error saying guild is not defined. I want it to remove a specific custom emoji when a user doesn't have a specific role I am kind of confused what to do anyone know the issue?

Hacker
  • 11
  • 2

1 Answers1

0

There are two issues. The first one, obviously, is that guild is not defined. Luckily, MessageReaction has a message property, which has a guild property.

const role = reaction.message.guild.roles.cache.find(
 (role) => role.name === 'specific role'
);

First of all, reaction doesn't have an author property. Even if it did, it would return a User object, which you can't access roles from. Read this answer to see the difference. Instead, you should use the Guild.member() function.

client.on('messageReactionAdd', async (reaction, user) => {
 const guild = reaction.message.guild;
 const role = guild.roles.cache.find((role) => role.name === 'specific role');

 if (
  reaction.emoji.id == '759643335043448834' &&
  guild.member(user).roles.has(role.id)
 )
  return;

 reaction.message.delete({ timeout: 2500 });
});
Lioness100
  • 8,260
  • 6
  • 18
  • 49