Home > Back-end >  Check if user is a server member
Check if user is a server member

Time:11-09

I want to check if certain user is a server member using their ID, but when I try to check it - my bot says user is not a server member even when he clearly is! Here is what I tried:

if(message.guild.members.cache.get('ID')) {
// ...code
}

What can I do to check it?

CodePudding user response:

The member isn't cached. Always fetch a user and don't rely on the cache.

const targetMember = await message.guild.members.fetch('ID');

if (target) {
   // Member is in the guild
} else {
   // Member is not in the guild
}
  • Related