diff --git a/src/rest/request_manager.ts b/src/rest/request_manager.ts index fdc116f36..4eacb42bf 100644 --- a/src/rest/request_manager.ts +++ b/src/rest/request_manager.ts @@ -423,5 +423,16 @@ function processHeaders(url: string, headers: Headers) { } } + if (ratelimited) { + eventHandlers.rateLimit?.({ + remaining, + bucketID, + global, + resetTimestamp, + retryAfter, + url, + }); + } + return ratelimited ? bucketID : undefined; } diff --git a/src/types/options.ts b/src/types/options.ts index 2ec6fd099..702c628c3 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -72,7 +72,23 @@ export interface DebugArg { data: unknown; } +interface RateLimitData { + /** The number of remaining requests that can be made */ + remaining: string | null; + /** Epoch time (seconds since 00:00:00 UTC on January 1, 1970) at which the rate limit resets */ + resetTimestamp: string | null; + /** Total time (in seconds) of when the current rate limit bucket will reset. Can have decimals to match previous millisecond ratelimit precision */ + retryAfter: string | null; + /** Returned only on a HTTP 429 response if the rate limit headers returned are of the global rate limit (not per-route) */ + global: string | null; + /** A unique string denoting the rate limit being encountered (non-inclusive of major parameters in the route path) */ + bucketID: string | null; + /** The URL the HTTP request is made to */ + url: string; +} + export interface EventHandlers { + rateLimit?: (data: RateLimitData) => unknown; applicationCommandCreate?: (data: Application) => unknown; /** Sent when properties about the user change. */ botUpdate?: (user: UserPayload) => unknown;