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

91
Vistas
DiscordJs - Member undefined when remove reaction first

im trying to make a basic bot add/remove role when add/remove reaction from a post on discord.

The code works if i add the role first and then remove it, but lets say i already have the role and restart the script. When i remove the reaction the script gives me the error saying: "Cannot read properties of undefined (reading 'roles')"

client.on('messageReactionRemove', async (reaction, user) => {
if (reaction.partial) {
    try {
        await reaction.fetch();
    } catch (error) {
        console.error('Something went wrong when fetching the message:', error);
        return;
    }
}

if (reaction.message.id != pinnedMsg) {
    return;
}
var role = reaction.message.guild.roles.cache.find(role => role.name === "ROLENAME");
const guild = reaction.message.guild;

const member = await guild.members.cache.find(member => member.id === user.id);

member.roles.remove(role); }); //var member is undefined here
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You need to fetch members with <Guild>.members.fetch because they are not cached. Don't forget to use await when needed, to find in cache it's not necessary.

Example for your case:

await guild.members.fetch();
const member = guild.members.cache.find(member => member.id === user.id);
about 4 years ago · Santiago Trujillo 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