mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(core): handle request all guild members rate limit (#11251)
* feat(core): handle request all guild members rate limit BREAKING CHANGE: `Gateway` now requires `off` `once` methods * fix: weird import update * refactor: error class * refactor: error class again * refactor: requested changes * chore: fix dep * fix: suggested changes --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
37a38883d7
commit
d3d6777ef8
@@ -61,6 +61,9 @@
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"funding": "https://github.com/discordjs/discord.js?sponsor",
|
||||
"dependencies": {
|
||||
"discord-api-types": "^0.38.31"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@discordjs/api-extractor": "workspace:^",
|
||||
"@discordjs/scripts": "workspace:^",
|
||||
|
||||
25
packages/util/src/gatewayRateLimitError.ts
Normal file
25
packages/util/src/gatewayRateLimitError.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { GatewayOpcodeRateLimitMetadataMap, GatewayRateLimitedDispatchData } from 'discord-api-types/v10';
|
||||
|
||||
/**
|
||||
* Represents the error thrown when the gateway emits a `RATE_LIMITED` event after a certain request.
|
||||
*/
|
||||
export class GatewayRateLimitError extends Error {
|
||||
public override readonly name = GatewayRateLimitError.name;
|
||||
|
||||
public constructor(
|
||||
/**
|
||||
* The data associated with the rate limit event
|
||||
*/
|
||||
public readonly data: GatewayRateLimitedDispatchData<keyof GatewayOpcodeRateLimitMetadataMap>,
|
||||
/**
|
||||
* The payload data that lead to this rate limit
|
||||
*
|
||||
* @privateRemarks
|
||||
* Too complicated to type properly here (i.e. extract the ['data']
|
||||
* of event payloads that have t = keyof GatewayOpcodeRateLimitMetadataMap)
|
||||
*/
|
||||
public readonly payload: unknown,
|
||||
) {
|
||||
super(`Request with opcode ${data.opcode} was rate limited. Retry after ${data.retry_after} seconds.`);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ export type * from './types.js';
|
||||
export * from './functions/index.js';
|
||||
export * from './JSONEncodable.js';
|
||||
export * from './Equatable.js';
|
||||
export * from './gatewayRateLimitError.js';
|
||||
|
||||
/**
|
||||
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/util#readme | @discordjs/util} version
|
||||
|
||||
Reference in New Issue
Block a user