Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

466
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda