how do a use the @discordjs/proxy?

as said ,I need http proxy best practice and websocket gateway proxy best practice . thank you .
10 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
Prolewin
ProlewinOP14mo ago
discord.js is "discord.js": "^14.13.0", nodejs v16.19.1. there is a proxyRequest method and i used it but its giving out const dotenv = require("dotenv"); dotenv.config(); const {Client, REST, GatewayIntentBits, Routes} = require("discord.js"); const {discordjsClientConfig, axiosConfig} = require('../../config'); const axios = require("axios"); const proxy = require('@discordjs/proxy'); const BASE_URL = "https://discord.com/api"; class Bot { baseURL = ""; version = 6; client = null constructor(config) { if (config) { this.version = config.version || this.version; } this.baseURL = ${BASE_URL}/v${this.version}; this.clientConnect(); } async clientConnect() { const commands = [ { name: 'ping', description: 'Replies with Pong!', }, ]; this.client = proxy.proxyRequests(new REST({version: '10'}).setToken(process.env.DISCORD_TOKEN)); try { console.log('Started refreshing application (/) commands.'); await this.client.put(Routes.applicationCommands("1163744048322990080"), { body: commands }); console.log('Successfully reloaded application (/) commands.'); } catch (error) { console.error(error); } } } ERROR: TypeError: this.client.put is not a function at Bot.clientConnect (D:\webstorm_projects\koa-gpt-xcx\src\util\discordBot.js:38:31) at new Bot (D:\webstorm_projects\koa-gpt-xcx\src\util\discordBot.js:23:14) at Object.<anonymous> (D:\webstorm_projects\koa-gpt-xcx\app.js:51:13) at Module._compile (node:internal/modules/cjs/loader:1191:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1245:10) at Module.load (node:internal/modules/cjs/loader:1069:32) at Function.Module._load (node:internal/modules/cjs/loader:904:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:22:47 but that is an dead end.i get this problem because the discordjs wont do a proxy setting ,if i use the proxy solutiong discordjs provides me it wont do (as before),so i have to use the discordsjs proxy setting but it doesnt have one ,so how am i gonna "connect to your proxy server from your localhost" without the discordjs ? i have been trying anything i know .last day you gave me the @discordjs/proxy-container,i posted it to the hongkong server . but it went 404 , you mean that is the right way ? sorry i will redo the whole thing again to get that error ...i shall do it now . i deleted the whole thing when i thought it was a dead wrong end hhhh sorry ... doing it right now .
Prolewin
ProlewinOP14mo ago
ok so the container started and opened by 3038port
No description
Prolewin
ProlewinOP14mo ago
server { listen 443 ssl; access_log /usr/local/nginx/logs/...cn.nginx.log; server_name .......cn; discordjsproxycontainer的镜像映射位置所在,请暂时不要动它。 location /discordjsproxycontainer { proxy_pass http://127.0.0.1:3038; proxy_set_header Connection ""; proxy_http_version 1.1; } } nginx config got it and reloaded DiscordAPIError[0]: 404: Not Found at handleErrors (D:\webstorm_projects\koa-gpt-xcx\node_modules@discordjs\rest\dist\index.js:687:13) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async SequentialHandler.runRequest (D:\webstorm_projects\koa-gpt-xcx\node_modules@discordjs\rest\dist\index.js:1072:23) at async SequentialHandler.queueRequest (D:\webstorm_projects\koa-gpt-xcx\node_modules@discordjs\rest\dist\index.js:913:14) at async _REST.request (D:\webstorm_projects\koa-gpt-xcx\node_modules@discordjs\rest\dist\index.js:1218:22) at async WebSocketManager.fetchGatewayInformation (D:\webstorm_projects\koa-gpt-xcx\node_modules@discordjs\ws\dist\index.js:1385:18) at async WebSocketManager.connect (D:\webstorm_projects\koa-gpt-xcx\node_modules\discord.js\src\client\websocket\WebSocketManager.js:168:9) at async Client.login (D:\webstorm_projects\koa-gpt-xcx\node_modules\discord.js\src\client\Client.js:226:7) { requestBody: { files: undefined, json: undefined }, rawError: { message: '404: Not Found', code: 0 }, code: 0, status: 404, method: 'GET', url: 'https://....cn/discordjsproxycontainer/api/v10/gateway/bot' } the error is here. and the code : clientConnect() { this.client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers, ], rest: { api: 'https://....cn/discordjsproxycontainer/api', } }); this.client.login().then(res => { console.log('result', res); this.server.connect = true; }).catch(rej => { console.log('reject', rej, '\nreconnecting'); this.server.connect = false; let timeout = setTimeout(() => { this.clientConnect(); clearTimeout(timeout) }, 2000) }); } ok wired its also 404
Prolewin
ProlewinOP14mo ago
No description
Prolewin
ProlewinOP14mo ago
wow~
Prolewin
ProlewinOP14mo ago
ok that is wierd ..........so im gonna try the image server address and see what happens.....but the image system works fine tough ,this is where i store some pic i need to grab ..
No description
Prolewin
ProlewinOP14mo ago
still 404 /api still 404 https://....cn/discordjsproxycontainer/api docker run -d --restart unless-stopped --name discordjs-proxy-container -p 127.0.0.1:3038:8080 this is how i built the container . i didnt altered it alot just the port it need to expose and the name .. remapping , with nginx discordjsproxycontainer的镜像映射位置所在,请暂时不要动它。 location /discordjsproxycontainer { proxy_pass http://127.0.0.1:3038; proxy_set_header Connection ""; proxy_http_version 1.1; } here... still 404 {"message":"404: Not Found","code":0}just not found ,... but this .....this is a nginx problem i guess ?means the request never reached the discord network at all . just 404 not found the container . ok news .it was a nginx problem .the location and the proxy_pass both needs a "/"in the back of their value to not consider the location value into the final prepared url . but now the problem is back to where its started . so the only reason why im doing all this is because the straight link from discordjs to discord is blocked and returning connect timeout error .but now ,with the container .its still returning ETIMEDOUT error new ,now it is giving out some error about some random ip address or dns address?i dont know about this so i have no idea reject Error: connect ETIMEDOUT 182.50.139.56:443 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16) { errno: -4039, code: 'ETIMEDOUT', syscall: 'connect', address: '182.50.139.56', port: 443 } reconnecting reject Error: connect ETIMEDOUT 168.143.162.58:443 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16) { errno: -4039, code: 'ETIMEDOUT', syscall: 'connect', address: '168.143.162.58', port: 443 } reconnecting see ?this is what it is giving out ,this looks like some random polling address some where in the network ,but this is unexceptable .cause when i use browser or curl to connect the "https://....cn/discordjsproxycontainer/api" it returns 'unauthorize' now ,and its correct cause i didnt give any authorization token so this is fucked up .cause the docker desktop container i started in my own computer is also posting this error .that means that the container in my own computer doesnt have a vpn problem because this one is the hongkong server and its not block by the firewall of our country. so this problem is actually related to the "connect ETIMEDOUT using ..." blablabla ...cause these are the same problem . and this is what my own computer's docker is giving out 2023-10-19 16:02:52 node:internal/process/promises:288 2023-10-19 16:02:52 triggerUncaughtException(err, true /* fromPromise /); 2023-10-19 16:02:52 ^ 2023-10-19 16:02:52 2023-10-19 16:02:52 Error: Client network socket disconnected before secure TLS connection was established 2023-10-19 16:02:52 at connResetException (node:internal/errors:720:14) 2023-10-19 16:02:52 at TLSSocket.onConnectEnd (node:_tls_wrap:1655:19) 2023-10-19 16:02:52 at TLSSocket.emit (node:events:529:35) 2023-10-19 16:02:52 at endReadableNT (node:internal/streams/readable:1368:12) 2023-10-19 16:02:52 at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { 2023-10-19 16:02:52 code: 'ECONNRESET', 2023-10-19 16:02:52 path: undefined, 2023-10-19 16:02:52 host: 'discord.com', 2023-10-19 16:02:52 port: 443, 2023-10-19 16:02:52 localAddress: null 2023-10-19 16:02:52 } 2023-10-19 16:02:52 2023-10-19 16:02:52 Node.js v18.18.2 2023-10-19 16:03:04 node:internal/process/promises:288 2023-10-19 16:03:04 triggerUncaughtException(err, true / fromPromise */); 2023-10-19 16:03:04 ^ 2023-10-19 16:03:04 2023-10-19 16:03:04 ConnectTimeoutError: Connect Timeout Error 2023-10-19 16:03:04 at onConnectTimeout (/usr/proxy-container/node_modules/.pnpm/[email protected]/node_modules/undici/lib/core/connect.js:186:24) 2023-10-19 16:03:04 at /usr/proxy-container/node_modules/.pnpm/[email protected]/node_modules/undici/lib/core/connect.js:133:46 2023-10-19 16:03:04 at Immediate._onImmediate (/usr/proxy-container/node_modules/.pnpm/[email protected]/node_modules/undici/lib/core/connect.js:174:9) 2023-10-19 16:03:04 at process.processImmediate (node:internal/timers:476:21) { 2023-10-19 16:03:04 code: 'UND_ERR_CONNECT_TIMEOUT' 2023-10-19 16:03:04 } 2023-10-19 16:03:04 2023-10-19 16:03:04 Node.js v18.18.2
Prolewin
ProlewinOP14mo ago
postman is pinged through
No description
Prolewin
ProlewinOP14mo ago
ok the old js actually working now ......wow this is not ...easy...wow ok ,so it was never about the proxy .the Client Class must have some sort of mistake .cause the REST is working perfectly . i guess it was the websocket somehow ? i dont know , i will know when i get there.. so that's my noon thinking when im walking to get some braised potatoes and chicken .i think the only reason that a pure get request is working and a login sending request is not is probably because that something else is building up connection that requires a long ,steady connection .i bet websocket but i dont know that sht much .so . cause the login is in-fact , a "gateway/bot" api component . whatever that is ,i didnt found it on the discord developers website.. but to that description about the "gateway "i think it needs constant connection . more then just a get ,still i dont understand why its a rest connection turns into a socket connection .obviously when we talk about websocket normally ,its just a websocket agreement patched to the http protocal. hhhhhwwwwww but how am i ...i dont even know what that is ...how am i gonna solve it wwwwahahahhahahhaha my brain must have ignore it to protect me from being harm by knowledge i dont know (hhhh) im setting up an issue to the discordjs team .i cant do this . ok....... ...dang it ....you ..oh my god thank you ,thank you and all those people helping me tough you are annoyed .thankyou .... its so fcking .the truth is so f*cking easy .i have a clash .all i need to do is to do a global speed up ... a servermode +TUN mode .one click and one button and we are there ...i oh... oh my god it took me more then six days on this from the beginning .oh my god .thank you . i have been doing tones of work .tone and tones ....wwwwwhahahahhah wwhsajfakljsflakj
Want results from more Discord servers?
Add your server