【问题标题】:Discord.js Bot rate limit [duplicate]Discord.js Bot速率限制[重复]
【发布时间】:2020-11-18 21:23:15
【问题描述】:

所以我想在线上传我的不和谐机器人,但我想防止用户向它的命令发送垃圾邮件。 所以让延迟为 5 秒,如果用户运行 !help 机器人会回答,但如果用户在延迟到期之前运行 !help,机器人会说:wait some time before using this command again。 此外,我希望延迟仅适用于消息作者,而不影响其他用户。 我正在使用命令处理程序,所以可以制作类似module.exports.delay 的东西吗?

【问题讨论】:

标签: node.js discord.js


【解决方案1】:

为此,您可以使用以下时间戳:

let msgTimestamp = [];
if(message.content === "?" + "help") {
    if(typeof msgTimestamp[0] !== "undefined") {
        if(msgTimestamp[0] + 5000 < Date.now()) {
            message.channel.send("Here embed of command help.");
            msgTimestamp = [];
        } else {
            message.channel.send("wait some time before using this command again.");
        }
    } else {
        msgTimestamp.push(Date.now());
        message.channel.send("Here embed of command help.");
    }
}

在此代码中,您使用时间戳,检查消息的内容是否与您要使用的命令一致,如果用户已经发送了消息,则包含消息时间戳的变量已满,然后检查如果变量的 typeof 不是未定义的,那么你检查 id 用户发送消息时的时间戳低于实际时间戳 + 你想要多少延迟!

【讨论】:

  • 帮助命令只是例如我希望它适用于所有命令
  • 然后调整将用于每个命令的代码
猜你喜欢
  • 2020-11-15
  • 2021-07-09
  • 2020-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-09
相关资源
最近更新 更多