【发布时间】:2020-11-22 00:53:04
【问题描述】:
我正在尝试了解 discord API 的工作原理。尤其是限速政策。通过阅读docs。我需要实现一个逻辑来跟踪在我执行请求时它作为响应标头发送的无效请求的速率。但是,当我使用邮递员执行此操作(请求)时,响应标头不包含this part of the docs 中显示的速率限制信息。因此,我不知道如何处理这个问题。
所以我有两个问题:
- 如何在响应中获取速率限制标头?
- 如何在我的代码中实现逻辑以防止我的后端在达到限制时发送请求并在下次尝试之前设置超时以避免我的 IP 被不和谐禁止?
我的 expressjs 代码示例:
const addnew = async (req, res) => {
try {
const { memberId, guildId, type, value, embed } = req.body;
res
.status(400)
.send({ error: "error" });
return;
await client.addnew(memberId, guildId, type, value, embed);
res.status(200).send(req.body);
} catch (err) {
console.log(err);
res.status(500).send(err);
}
};
【问题讨论】:
标签: node.js express http-headers discord.js rate-limiting