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

364
Views
El bot asigna un rol al usuario, incluso si el usuario no posee el rol

Perdón por el título confuso, lo aclararé. Estoy tratando de hacer que el bot verifique si un usuario tiene un rol determinado en su inventario de quick.db y, si lo tiene, equipará ese rol. El problema que tengo es que incluso con el rol en el inventario, devuelve el error de que el rol no es propiedad. Tengo la sensación de que el problema es la if (db.has(message.author.id + '.hot rod red')) , ya que no estoy muy seguro de cómo formatear la verificación de un rol con quick.db. Perdón por el código desordenado, si alguien sabe cómo solucionarlo, hágamelo saber, ¡gracias!

 if (db.has(message.author.id + '.hot rod red')) { if (message.member.roles.cache.some(role => role.name === 'hot rod red')) { let embed = new Discord.MessageEmbed().setDescription('You already have this role equipped!'); return message.channel.send(embed); } else { await message.guild.members.cache.get(user.id).roles.add('733373020491481219'); let embed = new Discord.MessageEmbed().setDescription(`You now have the ${message.guild.roles.cache.get('733373020491481219')} role!`); message.channel.send(embed); user.roles.remove(user.roles.highest); } } else { let embed = new Discord.MessageEmbed().setDescription('You do not own this role!'); // ERROR HERE; GIVES ROLE EVEN WITHOUT OWNING return message.channel.send(embed); }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Probablemente intente algo como let check = db.get(message.author.id+'.hot rod red') y verifique si es verdadero/falso, diría que use una cadena en lugar de booleano como puede usar if(check === 'false/true'){} . también puedes hacer

 if(!check || check === 'false'){ return let embed = new Discord.MessageEmbed().setDescription('You do not own this role!'); return message.channel.send(embed); }

Así que el código final sería:

 let check = await db.get(message.author.id + '.hot rod red'); let rejectEmbed = new Discord.MessageEmbed() .setDescription('You do not own this role!'); if(!check){ return message.channel.send(rejectEmbed) } if(check === 'true'){ if (message.member.roles.cache.some(role => role.name === 'hot rod red')) { let embed = new Discord.MessageEmbed().setDescription('You already have this role!'); return message.channel.send(embed); } else { await message.guild.members.cache.get(user.id).roles.add('733373020491481219'); let embed = new Discord.MessageEmbed().setDescription(`You now have the ${message.guild.roles.cache.get('733373020491481219')} role!`); message.channel.send(embed); user.roles.remove(user.roles.highest); // I'm unsure why this is here, this could be causing a potential error } }

Si hay más preguntas, por favor comenten!! Espero que esto haya ayudado.

over 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!