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

108
Vistas
Discord.js role not getting added with no errors

I'm trying to add a role to a user, but I’m getting no errors. I’m using a slash command.

let role = interaction.member.guild.roles.cache.find(r => r.name == "Amazing")
interaction.member.roles.add(role)

// interaction is from the interactionCreate event

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In discord.js v13 interaction.member does not have a function to add roles. I'd fetch the guildMember object then add the roles.

Example:

let guild = await client.guilds.fetch(interaction.guild_id)
let member = guild.members.cache.get(interaction.member.user.id);
let role = guild.roles.cache.find(r => r.name == "Amazing");
if (!role)
    return console.log("the role doesn't exist");
member.roles.add(role);

Full example:

const Discord = require("discord.js");
const client = new Discord.Client();

client.on("interactionCreate", async (interaction) => {
    ...
    let guild = await client.guilds.fetch(interaction.guild_id)
    let member = guild.members.cache.get(interaction.member.user.id);
    let role = guild.roles.cache.find(r => r.name == "Amazing");
    if (!role)
        return console.log("the role doesn't exist");
    member.roles.add(role);
});

client.login('Your-token');
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