How to find out how much time is left for setTimeout js?

  • 0
    I made a command / daily, which gives 50 Coins per account, but no more than once every 24 hours. How can I, instead of "Wait another ...." make it so that it displays when it will be possible to enter the command again, for example "Wait xx hours and yy minutes".
    module.exports.run = async (bot, message, args) => {
        const profile = require('../profile.json');
        if(profile[message.author.id].daily == 1) return message.channel.send('Подождите ещё ....')
        const bonus = 50;
        profile[message.author.id].coins = profile[message.author.id].coins + bonus;
        await message.reply(` вы получили бонус ${bonus} Coins!`);
        profile[message.author.id].daily = 1;
        setTimeout(() => {
            profile[message.author.id].daily = 0;
        }, 60 * 60000 * 24 );
    };
    JavaScript Anonymous, May 21, 2019

  • 1 Answers
  • 0
    Thanks to the comments, I did it like this.

    const profile = require('../profile.json');
    const x = Date.now();
    const y = Date.now() + 24 * 60 * 60000
    const bonus = 50;
    if(x <= profile[message.author.id].daily) return message.reply(` Вы ещё не можете активировать бонус $({profile[message.author.id].daily - x)} сек!`)
    else profile[message.author.id].coins += bonus
    profile[message.author.id].daily = y;
    message.reply(` на Ваш аккаунт зачислено ${bonus} Coins! Текущий баланс ${profile[message.author.id].coins}`)
    };
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!