I am trying to understand how the discord API works. Especially the rate limit policy. By reading the docs . I need to implement a logic that track the rate of invalid request that it sent as a response header when I do my requests. However, when I do it (the request) using postman, the response headers don't include the rate-limit info as showed in this part of the docs . Hence, I don't know how to handle this issue.
So I have two questions :
A sample of my expressjs code :
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);
}
};
Discord.js has logic that takes care of the rate limit issue for you. If you monitor the Client#rateLimit event, you can see that if you make too many API requests within your code, the event will trigger. This means that your requests have been enqueued and Discord.js will send them once your rate limit duration has been exceeded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With