feat: DiscordAPIError debug

This commit is contained in:
Elysia 2023-02-14 23:46:04 +07:00
parent a8c08822ff
commit 7f5df8fddb
3 changed files with 9 additions and 1 deletions

View File

@ -58,6 +58,12 @@ class DiscordAPIError extends Error {
json: request.options.data, json: request.options.data,
files: request.options.files ?? [], files: request.options.files ?? [],
}; };
/**
* The number of times this request has been retried
* @type {number}
*/
this.retries = request.retries;
} }
/** /**

View File

@ -389,7 +389,7 @@ class RequestHandler {
if ( if (
data?.captcha_service && data?.captcha_service &&
this.manager.client.options.captchaService && this.manager.client.options.captchaService &&
request.retries < 4 && request.retries <= this.manager.client.options.captchaRetryLimit &&
captchaMessage.some(s => data.captcha_key[0].includes(s)) captchaMessage.some(s => data.captcha_key[0].includes(s))
) { ) {
// Retry the request after a captcha is solved // Retry the request after a captcha is solved

2
typings/index.d.ts vendored
View File

@ -1273,6 +1273,7 @@ export class DiscordAPIError extends Error {
public path: string; public path: string;
public httpStatus: number; public httpStatus: number;
public requestData: HTTPErrorData; public requestData: HTTPErrorData;
public retries: number;
} }
export class DMChannel extends TextBasedChannelMixin(Channel, [ export class DMChannel extends TextBasedChannelMixin(Channel, [
@ -4911,6 +4912,7 @@ export interface ClientOptions {
captchaService?: captchaServices; captchaService?: captchaServices;
captchaKey?: string; captchaKey?: string;
captchaSolver?: (data: Captcha, userAgent: string) => Promise<string>; captchaSolver?: (data: Captcha, userAgent: string) => Promise<string>;
captchaRetryLimit?: number;
interactionTimeout?: number; interactionTimeout?: number;
usingNewAttachmentAPI?: boolean; usingNewAttachmentAPI?: boolean;
} }