soy un novato en la codificación y no sé cómo almacenar algo en la base de datos, específicamente necesito almacenar un temporizador en la base de datos. Básicamente, lo que tengo tiene un temporizador, por lo que el usuario no puede volver a usar algo determinado hasta que ese temporizador se apague. Necesito que el temporizador esté en la base de datos, de modo que si el bot se desconecta, los temporizadores se guardarán y no se reiniciarán/el usuario podrá usar esa cosa nuevamente. Actualmente estoy ejecutando 9the bot en discord v13.
Hay varios db para que usted logre esto
Aquí hay algunos:
• Quick.db
• MongoDB
Lea los documentos y estará listo para comenzar
El siguiente es un ejemplo de quick.db
const db = require('quick.db') db.set(`foo`, "bar")//An example on how to set //You can set the timestamp and the userid, read docs to help yourself out there const db = require('quick.db') const ms = require('ms') const prefix = "!" client.on("messageCreate", async message=>{ if(message.content.startsWith('!disable')){ let target = message.mentions.users.first()//Getting the user who was mentioned if(!target) return; //If no user is mentioned return target = target.id//User id of the mentioned user let args = message.content.slice(prefix.length).trim().split(' ') args.shift() let duration = ms(args[1]) if(isNaN(duration)) return message.reply({content: `Not a valid duration`}) await db.set(`disabled_${target}`, duration)//Setting the user and the timestamp in the db } }) //Checking on start client.on("ready", ()=>{ setInterval(()=> { let all = db.all() all = all.filter(data => data.ID.startsWith(`disabled_`)) for(var i in all){ if(Date.now() > all[i].data) { //Checking if it's the time to remove the user as disabled let id = all[i].ID.split('_')[1] db.delete(`disabled_${id}`)//Removing the user from the database console.log(`Removed user with ID ${id}`) } } }, 5000)//checking every 5 seconds }) })Esto es solo para su referencia, lo anterior se puede simplificar si usa comandos de barra oblicua
En caso de que opte por comandos heredados/barra, use un controlador de comandos, hay un ejemplo de lo mismo en la guía discord.js para tener todo bien organizado