【问题标题】:Cooldowns for Button Discordjs按钮 Discordjs 的冷却时间
【发布时间】:2021-12-04 23:35:03
【问题描述】:

我想知道如何为按钮设置冷却时间?就像如果有人按下一个按钮并试图向它发送垃圾邮件,机器人会受到速率限制,discord 也有按钮垃圾邮件检测功能,但到那时我的机器人会受到速率限制,这非常慢,有人可以帮忙吗?

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    这是您可以添加到interactionCreate 事件的解决方案

    // At the top of your file
    const buttonCooldown = new Set()
    
    client.on("interactionCreate", (ctx) => {
      if(!ctx.isButton()) return;
      if(buttonCooldown.has(ctx.user.id)) {
        // user is on cooldown, do whatever you want
      }
      buttonCooldown.add(ctx.user.id)
      setTimeout(() => buttonCooldown.delete(ctx.user.id), 10_000) // replace 10_000 with cooldown time
      // other logic here
    })
    
    

    【讨论】:

      猜你喜欢
      • 2021-05-09
      • 2021-05-15
      • 2021-02-16
      • 2021-06-17
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多