Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

465
Views
Discord.js cómo verificar si el usuario tiene un rol en un servidor específico

Estoy tratando de verificar si el usuario tiene un rol en un servidor específico, independientemente del servidor que use el bot.

Por ejemplo, si tengo 2 servidores, el servidor A y el servidor B, quiero verificar si el usuario tiene el rol "Principiante" en el servidor A, incluso si uso el comando en el servidor B.

No pude encontrar una manera de hacer esto en Internet, message.member.roles parece devolver solo los roles del servidor en el que se escribió el comando.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puedes hacerlo así:

 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); } }

Por supuesto, el bot tiene que estar en ambos servidores.

about 4 years ago · Juan Pablo Isaza Report

0

Una solución es encontrar el servidor y luego encontrar al miembro desde dentro del servidor.
Para encontrar el gremio, usará el guild.fetch(...) y desde allí usará la guildMember.fetch(...) para encontrar al miembro.

Ejemplo:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!