【发布时间】:2020-09-25 07:07:46
【问题描述】:
您好,我的问题很清楚。我有一个 setTimeout。当有人使用命令时,计时器被激活。如何找到 setTimeout() 中剩余的时间?找了一些资源,但是没用,有些资源需要时间到NaN
我能做什么?你们能帮帮我吗?
例子:waitsetTimeOut.setDescription('剩余时间2分钟')
这是我的代码,我的代码是最新的。
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"
};
【问题讨论】:
-
这能回答你的问题吗? find the time left in a setTimeout()?
-
不回答我的问题
标签: javascript discord discord.js