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

168
Views
DiscordJS GuildMemberRoleManager no tiene caché

Estoy tratando de ver si un usuario tiene un rol con discordjs v13. Estoy usando mecanografiado también.

En varias publicaciones, he visto a personas usar este código:

 function handleCommand(interaction: CommandInteraction) { ... let isAdmin = interaction.member.roles.cache.some(role => role.name === 'Admin') ...

Esto es un ejemplo

Sin embargo, me sale un error:

 Property 'cache' does not exist on type 'string[]'. 22 console.log(interaction.member.roles.cache.some((r) => r.name == "Admin")); ~~~~~

¿Cuál es la forma correcta de hacer esto?

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

0

Como señaló amablemente Elitezen, interaction.member.roles es una string[] en lugar de un GuildMemberRoleManager . ¡Lo lancé manualmente al tipo correcto y funcionó!

 let roles = (interaction.member.roles as GuildMemberRoleManager).cache; let isAdmin = roles.some( (role) => role.name === "admin") );
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!