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

473
Visualizações
Discord.js how to check if user has a role on a specific server

I'm trying to check if the user has a role on a specific server regardless on which server they use the bot.

For example, if I have 2 servers, server A and server B, I want to check if the user has the role "Beginner" on server A, even if I use the command in server B.

I couldn't find a way to do this on the internet, message.member.roles seems to only return the roles of the server the command was written in.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can do it like this:

function hasRole(guildId, roleId) {
    // Get second guild
    const guild = client.guilds.cache.get(guildId);

    // Get member in that guild, by ID
    const member = guild.members.cache.get(message.author.id);

    // If member is in that guild,
    if (member) {
        // return whether they have this role
        return member.roles.cache.has(roleId);
    }
}

Of course the bot has to be in both servers.

about 4 years ago · Juan Pablo Isaza Relatório

0

A solution is to find the server then find the member from inside the server.
To find the guild you will use the guild.fetch(...) method and from there you then use the guildMember.fetch(...) function to find the member.

Example:

client.on("messageCreate", function(message) {
    // Find the guild
    let guild = client.guilds.fetch("guild-id");
    // Find the member in the guild
    let member = guild.members.fetch(message.author.id);

    if (member)
        message.reply("You are in the server " + guild.name);
});
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