feat(Client): Support Proxy

- https://github.com/discordjs/discord.js/issues/3039#issuecomment-1033955220
- #283
(not tested yet)

Co-Authored-By: Nguyễn Hồng Đức <hongducyb123@gmail.com>
This commit is contained in:
March 7th
2022-08-29 11:10:47 +07:00
parent da93f6364d
commit 00a2b8aa5b
7 changed files with 19 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ const { setTimeout } = require('node:timers');
const FormData = require('form-data');
const JSONBig = require('json-bigint');
const fetch = require('node-fetch');
const proxy = require('proxy-agent');
let agent = null;
@@ -34,7 +35,10 @@ class APIRequest {
}
make() {
agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
agent ??=
typeof this.client.options.proxy === 'string' && this.client.options.proxy.length > 0
? new proxy(this.client.options.proxy)
: new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
const API =
this.options.versioned === false