命令的详细冷却时间

时间:2018-10-06 07:30:48

标签: node.js discord.js

我在一些不和谐的服务器上看到它们有详细的冷却时间,并且他们可以准确地看到需要多长时间才能再次使用该命令。 但是我不知道怎么添加,有人可以帮我吗?

我现在有这个

const talkedRecently = new Set();
if (talkedRecently.has(msg.author.id)) {
  msg.channel.send("Wait 1 minute before getting typing this again. - " + msg.author);
} else {
  talkedRecently.add(msg.author.id);
  setTimeout(() => {
    talkedRecently.delete(msg.author.id);
  }, 60000);
}

,但是在这里您看不到要等多久。我想要这样:
like this

3 个答案:

答案 0 :(得分:0)

如果创建冷却对象,则可以通过从冷却时间中减去日期来获得剩余的时间。

像这样:

__uint128_t bigIntBefore = 999999999999999999;
__uint64_t smallInt1;
__uint64_t smallInt2;
encode(bigIntBefore, smallInt1, smallInt2);

// ... later

__uint128_t bigIntAfter;
decode(smallInt1, smallInt2, bigIntAfter);
// bigIntAfter should have a value of '999999999999999999'

答案 1 :(得分:0)

const Discord = require("discord.js");
const fs = require("fs");
let coins = require("../coins.json");

module.exports.run = async (bot, message, args) => {

  var cooldowns = {}
  var minute = 60000;
  var hour = minute * 24;

    if(!coins[message.author.id]){
      coins[message.author.id] = {
        coins: 0
      };
    }
   let workAmt = Math.floor(Math.random() * 7) + 50;

if(cooldowns[message.author.id]){
if(cooldowns[message.author.id] > Date.now()) delete cooldowns[message.author.id];
  else message.channel.send("You have to wait " +    Math.round((cooldowns[message.author.id] - Date.now)/minute) + " minutes    before you can work again")
}
  coins[message.author.id] = {
    coins: coins[message.author.id].coins + workAmt
    };

    fs.writeFile("./coins.json", JSON.stringify(coins), (err) => {
    if (err) console.log(err)
      });
  message.channel.send(`You worked and you got ${workAmt} coins`)

  cooldowns[message.author.id] = Date.now() + hour * 24;
}

module.exports.help = {
  name: "work"
}

所以我就这样,但是当我使用cooldown命令时,它仍然不起作用,他运行了该命令,但是未激活cooldown。

答案 2 :(得分:0)

我还没有测试过,但是最简单的方法是:

display