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.