user17712850
user17712850

Reputation:

How do I check if a user has a specific role? | discord.js v13

How do I check if a user has a specific role? However, not by mentioning the user but through their ID. so, obviously this wouldn't work:

message.member.roles.cache.some(role => role.name === 'ROLE')

neither does client.users.cache.get('ID'); have a property allowing me to access their roles. neither does client.users.fetch. So how can I do it?

Upvotes: 1

Views: 3035

Answers (1)

MrMythical
MrMythical

Reputation: 9041

client.users.fetch() and client.users.cache.get() both return Users which don't have roles. You need to get a GuildMember from a guild

let member = guild.members.cache.get("id")
let hasRole = member.roles.cache.some(role => role.name === 'ROLE')

Upvotes: 1

Related Questions