diff --git a/src/rest/DiscordAPIError.js b/src/rest/DiscordAPIError.js index 9f633db..0e5ff06 100644 --- a/src/rest/DiscordAPIError.js +++ b/src/rest/DiscordAPIError.js @@ -58,6 +58,12 @@ class DiscordAPIError extends Error { json: request.options.data, files: request.options.files ?? [], }; + + /** + * The number of times this request has been retried + * @type {number} + */ + this.retries = request.retries; } /** diff --git a/src/rest/RequestHandler.js b/src/rest/RequestHandler.js index 1040c77..1bf8309 100644 --- a/src/rest/RequestHandler.js +++ b/src/rest/RequestHandler.js @@ -389,7 +389,7 @@ class RequestHandler { if ( data?.captcha_service && this.manager.client.options.captchaService && - request.retries < 4 && + request.retries <= this.manager.client.options.captchaRetryLimit && captchaMessage.some(s => data.captcha_key[0].includes(s)) ) { // Retry the request after a captcha is solved diff --git a/typings/index.d.ts b/typings/index.d.ts index 53c73b7..a993a9b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1273,6 +1273,7 @@ export class DiscordAPIError extends Error { public path: string; public httpStatus: number; public requestData: HTTPErrorData; + public retries: number; } export class DMChannel extends TextBasedChannelMixin(Channel, [ @@ -4911,6 +4912,7 @@ export interface ClientOptions { captchaService?: captchaServices; captchaKey?: string; captchaSolver?: (data: Captcha, userAgent: string) => Promise; + captchaRetryLimit?: number; interactionTimeout?: number; usingNewAttachmentAPI?: boolean; }