Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

244
Vistas
Discord.js command cooldowns with ms and quick.db

I want to set cooldown on the /rep command. But I have the problem. When user use command, the cooldown is correct. But when user run command secondly, the second cooldown is wrong, it is 52 years but it must be 12 hours. Why? There is my code. I have setted 15 seconds cooldown for testing, but it show 52 years from second cooldown and onwards. There isn't any error and console. Discord.js v13 and pretty-ms v7.0.1

const { SlashCommandBuilder } = require("@discordjs/builders");
const { MessageEmbed } = require("discord.js");
const db = require("quick.db");
const ms = require("pretty-ms");
const yaml = require('js-yaml');
const fs = require("fs");
const lang = yaml.load(fs.readFileSync('lang.yml', 'utf8'));

module.exports = {
    data: new SlashCommandBuilder()
        .setName('rep')
        .setDescription(lang.rep.cmdDesc)
        .addUserOption(option =>
            option.setName('user')
                .setDescription(lang.rep.optionDesc)
                .setRequired(true)),
    async execute(interaction) {
        let lastDaily = await db.fetch(`repCheck_${interaction.user.id}`);
        const cooldown = 15000;
        
        if (lastDaily !== null && cooldown - (Date.now() - lastDaily) > 0) {
            const timeLeftRep = ms(cooldown - (Date.now() - lastDaily))
            const timerr = new MessageEmbed()
            .setDescription(lang.rep.cooldownErr.replace('{{cooldownRep}}', timeLeftRep))
            .setColor('RED')
            await interaction.reply({ embeds: [timerr], ephemeral: true })
        } else if (interaction.options.getUser('user').bot) {
            const boterr = new MessageEmbed()
            .setDescription(lang.rep.mentionErr)
            .setColor('RED')
            await interaction.reply({ embeds: [boterr], ephemeral: true });
        } else if (interaction.options.getUser('user').id == interaction.user.id) {
            const selfmen = new MessageEmbed()
            .setDescription(lang.rep.selfMention)
            .setColor('RED')
            await interaction.reply({ embeds: [selfmen], ephemeral: true })
        } else {
            const member = interaction.options.getUser('user').id;
            let reputation = db.fetch(`rep_${member}`)
            db.add(`rep_${member}`, 1)
            const repembed = new MessageEmbed()
            .setDescription(lang.rep.successMsg.replace('{{user}}', interaction.options.getUser('user').username))
            await interaction.reply({embeds: [repembed]});
            db.add(`repCheck_${interaction.user.id}`, Date.now())
        }
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As I can't comment. It might be because you put db.add() instead of db.set() in your code. It will add your last cooldown time with the current cooldown time that you just set. Which is will make it longer. You can try to change your code :

from

db.add(`repCheck_${interaction.user.id}`, Date.now());

to

db.set(`repCheck_${interaction.user.id}`, Date.now());

And it maybe work, tell me if its not.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda