Javascript 将命令的等待时间设置为所有用户:setTimeout

Javascript 将命令的等待时间设置为所有用户:setTimeout,javascript,discord,discord.js,Javascript,Discord,Discord.js,我设定了等待时间!corona命令它工作正常,但我想删除一个等待时间,当用户输入的国家或地区不正确。我所有的代码如下 简而言之,当输入错误的国家/地区命令时,例如“!corona US”应在无等待时间的情况下查询新的国家/地区命令 实际上这很好,但是两个人可以同时启动这个命令。输入命令后,我希望每个人都有一段等待时间。这只为使用它的成员提供等待时间 const Discord=require(“Discord.js”); const fetch=require(“节点获取”); const h

我设定了等待时间!corona命令它工作正常,但我想删除一个等待时间,当用户输入的国家或地区不正确。我所有的代码如下

简而言之,当输入错误的国家/地区命令时,例如“!corona US”应在无等待时间的情况下查询新的国家/地区命令

实际上这很好,但是两个人可以同时启动这个命令。输入命令后,我希望每个人都有一段等待时间。这只为使用它的成员提供等待时间

const Discord=require(“Discord.js”);
const fetch=require(“节点获取”);
const hereTimeOut=新集合();
exports.run=async(bot、消息、参数)=>{
if(hereTimeOut.has(message.author.id)){
const waitsetTimeOut=new Discord.RichEmbed()
waitsetTimeOut.setColor(0x00AE86)
waitsetTimeOut.setTimestamp()的
waitsetTimeOut.setAuthor(message.author.username、message.author.avatarURL)
setTitle(“[等待一段时间]”)
waitsetTimeOut.setDescription('请等待1分钟')
返回message.channel.sendebed(waitsetTimeOut);
}否则{
让country=args.slice(0.join)(“”);
如果(!国家){
取回(“https://covid19.mathdro.id/api/)然后(res=>res.json())。然后(json=>{
const embed=new Discord.RichEmbed();
embed.addField(“**=案例总数=**”,`**`+json.confirm['value']+`person**`)
embed.addField(“**=治愈案例数=**”,`**`+json.recovered['value']+`person**`)
embed.addField(“**=丧失生命的案例数=**”,`**`+json.death['value']+'person**`)
嵌入.setColor(15962634)
嵌入.setTitle(“全球新冠病毒-19统计数据”)
message.channel.send({embed:embed});
});
}否则{
取回(`https://covid19.mathdro.id/api/countries/${country}`)。然后(res=>res.json())。然后(json=>{
const embed=new Discord.RichEmbed();
embed.addField(“**=案例总数=**”,`**`+json.confirm['value']+`person**`)
embed.addField(“**=治愈案例数=**”,`**`+json.recovered['value']+`person**`)
embed.addField(“**=丧失生命的案例数=**”,`**`+json.death['value']+'person**`)
嵌入.setColor(15962634)
嵌入.setTitle(`COVID-19统计数据(${country})`)
message.channel.send({embed:embed});
}).catch(()=>{
message.reply(“我找不到你要找的国家,在写国家时小心不要用土耳其语字母。你也可以写国家缩写(例如:TR,USA,AZ)”;
});
}
hereTimeOut.add(message.author.id);
设置超时(()=>{
//一分钟后将用户从集合中移除
hereTimeOut.delete(message.author.id);
}, 60000);
}
};
exports.conf={
启用:对,
吉登利:是的,
别名:['corona'],
级别:0
};
exports.help={
名称:“科罗纳”,
描述:“covid19”,
用法:“冠状病毒”

};您可以使用变量来存储命令是否可用,然后可以按如下方式对其进行编辑:

//设置
让isAvailable=真,
冷却时间=5000;//以毫秒计,这是5秒
//运行该命令时:
如果(可用){
isAvailable=false
设置超时(()=>{
isAvailable=true
},冷却时间)
//运行您的命令。。。
}否则{
//命令仍在冷却,请向用户发送消息让他们知道
}