Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

408
Visualizações
Discord.js: How can you check if a specific user has a role?

I'm looking to see if you can check if you can test for a specific user having a role. Only problem is that I'm fairly new to Discord.js and everything I searched up was either outdated, was something I couldn't fully understand or only showed how to test if the author of the message has the role, which is not what I'm trying to find out. What should I change in my current coding?

if (message.member.permissions.has("MANAGE_ROLES")) {

            const member = message.mentions.users.first();
            const memberTarget = message.guild.members.cache.get(member.id);
            const role = message.guild.roles.cache.find(role => role.name === "Awesome Role Name");

            if (memberTarget.roles.cache.has(role)) {
                message.channel.send(`${memberTarget} has the role!`);

            } else {
                message.channel.send(`${memberTarget} does not have the role!`);
            }
        }
    }
};
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

All you have to do is check if the GuildMember.roles.cache has the role. Also, the reason your code isn’t working is because you are using the role object. You need to use the role ID.

if (memberTarget.roles.cache.has(role.id))

More related things:

Getting role by any property

if (memberTarget.roles.cache.some(r => r.name === 'role-name'))
//does not need to be the name

Getting message author's roles

if (message.member.roles.cache.has(role.id))
about 4 years ago · Juan Pablo Isaza Relatório

0

To check for a role you can do the code:

if (member.roles.cache.has("ROLE_ID"))

If you wanted to check if the sender has the role you could do:

if (message.member.roles.cache.has("ROLE_ID")) {
    console.log(true);
} else {
    console.log(false);
}

If you wanted to check if someone else has a role you could do:

if (memberTarget.roles.cache.has("ROLE_ID")) {
    console.log(true);
} else {
    console.log(false);
}

To get a member you could do it in many different ways, one method would be to get them by mentions:

// This will get the first mention who is a member in the server
const memberTarget = message.mentions.members.first()

Read about guild member roles here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda