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 :
- How to get rate-limit headers in the response ?
- How to implement the logic in my code to prevent my backend to send a request if the limit has been reached and set a timeout before the next try in order to avoid my IP to be banned by discord ?
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);
}
};