Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

362
Visualizações
Bot assigns user a role, even if user doesn't own role

Sorry for the confusing title, I'll clarify. I'm trying to make the bot check if a user has a certain role in their quick.db inventory, and if they do, it'll equip that role. The problem I'm having is that even with the role in the inventory, it returns the error that the role isn't owned. I have a feeling that the problem is the if (db.has(message.author.id + '.hot rod red')) line, as I'm not too sure how to format checking for a role with quick.db. Sorry for the messy code, if anyone knows how to fix this let me know, thanks!

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 Respostas
Responde à pergunta

0

Probably try something like let check = db.get(message.author.id+'.hot rod red') and check if it is true/false, I'd say to use string rather then boolean as you can use if(check === 'false/true'){}. You can also do

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

So the final code would be:

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
  }
}

If there are any more questions, please comment!! I hope this has helped.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda