Discord.js Bot速率限制 [英] Discord.js Bot rate limit

查看:94
本文介绍了Discord.js Bot速率限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想在线上传我的Discord机器人,但我想防止用户向其发送垃圾邮件.因此,如果用户运行!help 机器人应答,则延迟时间为5秒,但是如果用户在延迟过期之前运行!help ,则机器人说: wait some再次使用此命令之前的时间.我也希望延迟仅适用于消息作者,而不影响其他用户.我正在使用命令处理程序,所以可以制作类似 module.exports.delay 的东西吗?

So i want to upload my discord bot online but i want to prevent users from spamming it's commands. So let the delay be 5 seconds, if user runs !help the bot answers, but if user run !help before the delay is expired bot says: wait some time before using this command again. Also i want the delay to work only for message author and not affect other users. I'm using command handler so is it possible to make something like module.exports.delay?

推荐答案

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

to do that you can use timestamps like:

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,则用户发送消息的时间戳小于实际时间戳+您想要多少延迟!

In this coode you use timestamps, you check if the content of the message is eualt to the command you want to use, if the user had already sent a message, the variable which containing the message timestamp is full, you check then if the the typeof of the variable is not undefined and then you check id the timestamp of when the user sent the message is lower than the actual timestamp + how many delay you want!

这篇关于Discord.js Bot速率限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆