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

119
Views
TypeErr: no se puede leer la propiedad 'roles' de undefined

Estoy tratando de crear un sistema de botones donde, si no tiene un rol específico, no puede usar un botón. Sin embargo, el código que he creado no parece funcionar.

 collector.on('collect', async interaction => { const wikiStaffRole = interaction.user.guild.roles.cache.find(role => role.name == "Staff"); if (interaction.customId === "yes") { if (!wikiStaffRole) { return interaction.followUp({ content: `${interaction.user} dude you need to be a staff member`, ephmeral: true }); } newUserEmbed.edit({ embeds: [], content: 'This report has been marked as completed.', components: [] }); return; } else if (interaction.customId === "no") { if (!wikiStaffRole) { return interaction.followUp({ content: `${interaction.user} dude you need to be a staff member`, ephmeral: true }); } newUserEmbed.edit({ embeds: [], content: 'This report has been denied.', components: [] }); return; } else if (interaction.customId === "what") { if (!wikiStaffRole) { return interaction.followUp({ content: `${interaction.user} dude you need to be a staff member`, ephmeral: true }); } newUserEmbed.edit({ embeds: [], content: 'This report has been marked as inconclusive.', components: [] }); return; } });

En cambio, recibo un error que indica que no puede leer la propiedad 'roles' de undefined. No puedo encontrar ninguna manera de arreglar esto.

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

0

Intentó acceder a la propiedad de guild inexistente de un objeto User . Esta propiedad no existe en los User s, pero sí en los objetos GuildMember e Interaction . Este código debería funcionar:

 const wikiStaffRole = interaction.guild.roles.cache.find(role => role.name == "Staff")

Tenga en cuenta que si no está en un gremio, esto arrojará un error. Puede usar el encadenamiento opcional ( ?. ) para evitar eso

 const wikiStaffRole = interaction.guild?.roles.cache.find(role => role.name == "Staff")

Sin embargo, creo que querías verificar si el miembro tenía el rol. En realidad, está comprobando si todo el servidor tiene el rol. Esto verificará solo los roles de los miembros.

 const wikiStaffRole = interaction.member?.roles.cache.find(role => role.name == "Staff") //optional chaining because member would be null if it was sent in a DM
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!