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

99
Views
DiscordJs - Miembro indefinido cuando se elimina la reacción primero

Estoy tratando de hacer que un bot básico agregue/elimine el rol cuando agregue/elimine la reacción de una publicación en Discord.

El código funciona si agrego el rol primero y luego lo elimino, pero digamos que ya tengo el rol y reinicio el script. Cuando elimino la reacción, el script me da el error que dice: "No se pueden leer las propiedades de undefined (leyendo '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 answers
Answer question

0

Debe buscar miembros con <Guild>.members.fetch porque no están en caché. No olvide usar await cuando sea necesario, para buscar en caché no es necesario.

Ejemplo para tu caso:

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