0

Hi my question is very clear. I have a setTimeout. timer is activated when someone uses a command. How do find the time left in a setTimeout()? I found a few resources, but it didn't work, some resources take time to NaN

What can I do? Can you help me guys?

Example : waitsetTimeOut.setDescription('remaining time 2 minutes')

here are my codes, my codes are up to date.

const Discord = require("discord.js");
const fetch = require("node-fetch");
const hereTimeOut = new Set();
let user = 1;

exports.run = async (bot, message, args) => {
    if (hereTimeOut.has(user)) {

        const waitsetTimeOut = new Discord.RichEmbed()
        waitsetTimeOut.setColor(0x00AE86)
        waitsetTimeOut.setTimestamp()
        waitsetTimeOut.setAuthor(message.author.username, message.author.avatarURL)
        waitsetTimeOut.setTitle("[wait a while]")
        waitsetTimeOut.setDescription('please wait 1 minute')
        return message.channel.sendEmbed(waitsetTimeOut);
    }else {


    let country = args.slice(0).join(' ');

    if(!country){

        fetch("https://covid19.mathdro.id/api/").then(res => res.json()).then(json => {

            const embed = new Discord.RichEmbed();
                embed.addField("**= Total Number of Cases =**",`**`+ json.confirmed['value'] +` person**`)
                embed.addField("**= Number of Healing Cases =**",`**`+ json.recovered['value'] +` person**`)
                embed.addField("**= Number of Cases Losing Life =**",`**`+ json.deaths['value'] +` person**`)
                embed.setColor(15962634)
                embed.setTitle('Worldwide COVID-19 Statistics')
            message.channel.send({embed: embed});

        });

    }else{

        fetch(`https://covid19.mathdro.id/api/countries/${country}`).then(res => res.json()).then(json => {

                const embed = new Discord.RichEmbed();
                    embed.addField("**= Total Number of Cases =**",`**`+ json.confirmed['value'] +` person**`)
                    embed.addField("**= Number of Healing Cases =**",`**`+ json.recovered['value'] +` person**`)
                    embed.addField("**= Number of Cases Losing Life =**",`**`+ json.deaths['value'] +` person**`)
                    embed.setColor(15962634)
                    embed.setTitle(`COVID-19 Statistics (${country})`)
                message.channel.send({embed: embed});

        }).catch(() => {

            message.reply("I couldn't find the country you are looking for, be careful not to use Turkish letters when writing the country. You can also write country abbreviations (ex: TR, USA, AZ)");

        });

    }

    hereTimeOut.add(user);
        setTimeout(() => {
          hereTimeOut.delete(user);
        }, msConvert(country));
    }

};

exports.conf = {
  enabled: true,
  guildOnly: true,
  aliases: ['corona'],
  permLevel: 0
};

exports.help = {
  name: "corona",
  description: "covid19",
  usage: "coronavirus"
};
Burcu
  • 57
  • 6

1 Answers1

0

I know I'm late but this should do (I guess)

GetTimeLeft(timeout) => {
    return(Math.ceil((timeout._idleStart + timeout._idleTimeout - Date.now()) / 1000));
}
let Timeout = setTimeout(() => {
    //Your code here
}, 3600000);

Then you can call this anywhere

console.log(GetTimeLeft(Timeout);

In your case put in in a command

Akio
  • 721
  • 2
  • 6
  • 21