diff --git a/src/rest/APIRequest.js b/src/rest/APIRequest.js index 22108a2..af001f4 100644 --- a/src/rest/APIRequest.js +++ b/src/rest/APIRequest.js @@ -106,6 +106,9 @@ class APIRequest { 'base64', ); } + if (this.options.mfaToken) { + headers['X-Discord-Mfa-Authorization'] = this.options.mfaToken; + } let body; if (this.options.files?.length) { diff --git a/src/rest/RequestHandler.js b/src/rest/RequestHandler.js index 8872143..6f30a16 100644 --- a/src/rest/RequestHandler.js +++ b/src/rest/RequestHandler.js @@ -355,6 +355,7 @@ class RequestHandler { let data; try { data = await parseResponse(res); + // Captcha if ( data?.captcha_service && typeof this.manager.client.options.captchaSolver == 'function' && @@ -384,6 +385,29 @@ class RequestHandler { request.retries++; return this.execute(request, captcha, data.captcha_rqtoken); } + // Two factor + if (data?.code && data.code == 60003 && request.options.mfaCode && request.retries < 1) { + this.manager.client.emit( + DEBUG, + `${data.message} + Method : ${request.method} + Path : ${request.path} + Route : ${request.route} + mfaCode : ${request.options.mfaCode}`, + ); + // Get ticket + const mfaData = data.mfa; + const mfaPost = await this.manager.client.api.mfa.finish.post({ + data: { + ticket: mfaData.ticket, + data: request.options.mfaCode, + mfa_type: 'totp', + }, + }); + request.options.mfaToken = mfaPost.token; + request.retries++; + return this.execute(request); + } } catch (err) { throw new HTTPError(err.message, err.constructor.name, err.status, request); }