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?
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 });
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.