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

173
Visualizações
How to make Timed role command with database, so after bot restart, time won't reset?

I am making a timed role command. I know that if I use setInterveral(), it will be deleted after restarting bot. Therefore, I tried using quick.db to store user IDs and also the time into the database. I tried fetching db when a user type anything, it works, but what I want is that I don't need to type any command, if time ended, role will be removed from the user of database. Here is my code:

message.reply({ embeds: [
        new Discord.MessageEmbed()
        .setTitle(`Role added`)
        .setDescription(`You got the role for a 1 week`)
      ]})
      db.set(`role_${message.author.id}`, Date.now())
      let role = message.guild.roles.cache.find(role => role.id === '873283387144691723')
      message.member.roles.add(role)
      db.push(`role_${message.guild.id}`, { week:`${message.member.id}`})

index.js:

client.on('messageCreate', message => {
    let members = db.fetch(`role_${message.guild.id}`)
    if(members !== null && members.find(x => x.week === message.author.id).week) {
      let timeout = 6048;
      let duration = db.fetch(`role_${message.author.id}`)
      
      if(timeout - (Date.now() - duration) <= 0) {
        let role = message.member.roles.cache.find(role => role.id === '873283387144691723')
        message.member.roles.remove(role)
      } else {
        let timeout = 6048;
        let date = db.fetch(`role_${message.member.id}`)
        message.channel.send(`${ms(timeout - (Date.now() - date), { long: true })}`)
      }
    } else {
      return;
    }
}

What should I do if I want the bot to auto remove the role after the time of users in database ended?

Note: I want to add multiple user in db also.

about 4 years ago · Juan Pablo Isaza
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