V
V
Vlad Morkovkin2021-06-20 00:29:44
Node.js
Vlad Morkovkin, 2021-06-20 00:29:44

How to check if a discord.js user has a role?

I tried to write:
if(message.member.roles.has(role.id))
but it does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlmondPark33609, 2021-06-20
@Vlad808

Checking for a role by name or id:
By name:

let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]))
if (rUser.roles.cache.find(role => role.name == "Название роли")) message.channel.send("Роль всё таки есть ;)")

By id: we do everything the same, only change role.name to role.id
if (rUser.roles.cache.find(role => role.id == "айди роли")) message.channel.send("Роль всё таки есть ;)")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question