简体   繁体   中英

How to return reactor who doesnt have spesicific role

Hello so I wanted to make my giveaway cannot be entered, unless he has the requirement role

here's my code

const filter = (reaction) => {
    reaction.emoji.name === '🎉'
};
let collector = message.createReactionCollector(filter, {time: ms(giveawayDuration)});

collector.on('collect', (reaction, user) => {
    if (reaction.emoji.name === '🎉' && !reaction.member.roles.cache.has(`${roleRequirement}`)) {
        console.log('he is not in')
        reaction.users.remove()
    }
})

I don't know why, but it doesnt remove the user's react, how do I change that

member is not a property ofMessageReaction . Instead, use the Guild.member() function, and pass the user parameter as an argument.

if (
 !message.guild.member(user).roles.cache.has(roleRequirement)
) // I removed the emote verification, as it is already included in the filter

Also, by emitting the user parameter in reaction.users.remove() , the argument defaults to this.reaction.message.client.user , which I don't think is what you want. Instead, pass the user.id property.

reaction.users.remove(user.id)

Another problem might be with the roleRequirement variable. Since you are using Collection.has() , make sure roleRequirement is the role ID , not the role object.

The filter is a function that should return a boolean or Promise<boolean> which in this case isn't returning anything, so probably isn't collecting any message either. (maybe you confused the brackets, you should be using in this scenario () instead of {} to specify return, or use any)

Anyway, as you want to delete any reaction that isn't :tada: you might as well just return true to collect every reaction.

There is no such object as MessageReaction.members . You will have to get the GuildMember by other means. Like:

const member = message.guild.members.cache.get(user.id);

Your final command may look like this:

const filter = reaction => true;
const collector = message.createReactionCollector(filter, { time: duration });

collector.on('collect', (reaction, user) => {
  const member = message.guild.members.cache.get(user.id);

  if(reaction.emoji.name !== '🎉' || !member.roles.cache.has(`roleId`)) {
    reaction.users.remove(user);
  }
});

If I misunderstood you and you want to keep the reactions other than :tada: and filters only those in which the member isn't in the role, change the filter and remove the verification if it's :tada: in the if statement as it becomes not necessary:

// filter become this
const filter = reaction => reaction.emoji.name === '🎉';

// there's no need for the :tada: if anymore
if(!member.roles.cache.has(`roleId`)) {

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM