【问题标题】:Cooldown command to check every cooldown (Discord.js)用于检查每个冷却时间的冷却命令 (Discord.js)
【发布时间】:2021-02-16 07:53:58
【问题描述】:

好的,假设我想创建一个命令来获取每个冷却时间并将其显示在嵌入中。我得到了嵌入部分,但是,每当我尝试“获得”冷却时间时,它就什么也做不了。我在不同的 js 文件上都有每个地图,我认为这是问题所在,但是,有什么我可以做的,这样我就不必重写主文件上的所有内容了吗?

下面是每个带有冷却时间的命令的代码示例:

const cooldownsdaily= new Map();
const duration = require ('humanize-duration');

这是用来设置的

cooldownsdaily.set(message.author.id, Date.now() + 86400000);
setTimeout(() => cooldownsdaily.delete(message.author.id), 86400000);

最后一个是我目前用来检查它是否被执行的那个,无论是在冷却命令还是在每日任务中

const cooldowndaily = cooldownsdaily.get(message.author.id);
if (cooldowndaily) {
        var remainingdaily = duration(cooldowndaily - Date.now(), { units: [`h`,`m`,`s`], language: "es" , round: true})
} if (!cooldowndaily) {
        var remainingdaily = ':white_check_mark:'
}

注意:如果有人可以帮助我解决这个问题,我会很高兴,解释(如果有的话)解决方案,以便我学习。我不只想要代码:

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    如果您想为某个特定命令设置冷却时间,请添加let cooldown = new Set(); 和: let cdseconds = 30; 到命令顶部,并在其正下方添加:

    let cooldownReply = new Discord.MessageEmbed()
        .setColor("RANDOM")
        .setTitle(message.author.tag + " Slow it down bruh..")
        .setDescription(
          "You're on cooldown! Please wait before using this command again!"
        );
      if (cooldown.has(message.author.id)) {
        message.delete();
        return message.channel.send(cooldownReply);
      }
      cooldown.add(message.author.id);
      setTimeout(() => {
        cooldown.delete(message.author.id);
      }, cdseconds * 1000);
    

    这将为一个命令设置 30 秒的冷却时间。如果您想要所有命令的冷却时间,只需在顶部添加:let cooldown = new Set(); let cdseconds = 30;,如果您不确定,请在第 4-7 行某处。还要确保将我在上面发送的嵌入和内容也添加到所有命令中。抱歉,如果这听起来令人困惑,请告诉我!

    【讨论】:

    • 正如我所说,我正在寻找一个通用的冷却命令,而不是如何添加冷却:imgur.com/dUrmUtv
    • 哦,好吧,我的错
    猜你喜欢
    • 2021-06-17
    • 2021-05-20
    • 2020-05-27
    • 2021-02-11
    • 2021-10-10
    • 1970-01-01
    • 2017-11-21
    • 1970-01-01
    • 2021-03-11
    相关资源
    最近更新 更多