为什么我被禁止使用 discord api?

Why am I blocked from using the discord api?

我正在编写一个 discord bot,我随机遇到了这个错误。据我所知,我暂时被 discord.py api 屏蔽了,但是“超出速率限制部分是什么意思?”

discord.errors.HTTPException: 429 Too Many Requests (error code: 0): You are being blocked from accessing our API temporarily due to exceeding our rate limits frequently. Please read our docs at https://discord.com/developers/docs/topics/rate-limits to prevent this moving forward.

超过速率限制意味着 discord API 明确地 告诉您您无法从他们的 API 中读取给定数量的更多数据时间。

查看他们的 rate limit docs,速率限制因您与之通话的端点而异:

The HTTP API implements a process for limiting and preventing excessive requests in accordance with RFC 6585. API users that regularly hit and ignore rate limits will have their API keys revoked, and be blocked from the platform. For more information on rate limiting of requests, please see the Rate Limits section.

为了提供帮助,他们方便地 return 一些关于您在他们的速率限制方面的立场的信息:

X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1470173023
X-RateLimit-Bucket: abcd1234
...

如果您使用的是 requests 库,您可以轻松检查您是否接近超过速率限制:

req = requests.get("https://discord.com/api/path/to/the/endpoint")

req.headers["X-RateLimit-Remaining"] # How many more requests you can make before `X-RateLimitReset`