Discord WebSocket Proxy

#1

If you want to receive events in real time, look at my second reply.

There seems to be some confusion, this is not a Webhook proxy. This is a WebSocket proxy. WebSockets are used for real time communication between a client and a server, discord uses WebSockets for connecting to their gateway, which is what allows you to receive all the events discord sends (Message created, user banned, etc) in real time.

This is a WebSocket proxy I’ve made to allow you to easily connect to any WebSocket server.
This was made because I figured people would want to connect to Discord, however it can connect to any WebSocket server. This also complies with Discord’s ToS because you are consuming their gateway.

This will allow you to receive near real-time events from Discord (or any WebSocket server you connect to), such as messages, bans, deleted messages, etc.

Setting up the server
You have to have Node installed before doing the below steps.

You’ll want to download my github repo and copy the Node-JS folder somewhere.
Inside of that folder, you’ll want to run npm i in your command line to install all the dependencies.
From there, you can run node . to start the server.

Node.JS Config
Inside of the index.js file, there will be a few options you can change.
Port will change the port that the WebSocket proxy will listen on, this allows you to run multiple proxies without any issues.

IdleTimeout will change how long until the WebSocket proxy will close the connection from inactivity.

Authentication will prevent unauthorized access by adding a password.

maxMessagesPerRecieve will set the max amount of messages sent everytime Roblox requests for messages.

Roblox Module
You’ll want to create a new ModuleScript and paste the source of the WebSocket module into it.
Any scripts that want to use it will have to require it.

Module API
The module API is a bit big to post here, so I’ve posted it on the github here.

As for connecting with Discord, I’ve made an example here. This is a fairly rough example, but it shows how to use the module and does connect to Discord. This only captures messages, however you can capture a lot more by checking Discord’s documentation.

If you need any help setting this up, any issues, bugs, need clarification, etc feel free to tell me here or in DMs.

17 Likes
Fireboltofdeath - Scripter / Web Developer
closed #2

This topic was automatically closed after 1 minute. New replies are no longer allowed.

opened #3
#4

I’ve created a new branch for my WebSocket proxy that can receive events in real time (little to no latency, aside from normal network latency) by using long polling.
Everything stays the same, however there are only two changes.

The Roblox module’s StartListen delay parameter is gone (for obvious reasons.)

There is a new settings in the Node.JS file
LongPollTimeout will determine how many seconds until a request gets sent to Roblox after no messages. Roblox will make a request directly after the timeout.

There were no changes to the APIs, and anything that previously worked with this should still work.
I’ve put the real time into a seperate branch because this can spam your HTTP if you receive a lot of requests.
Setup and everything else should be the exact same!

Real Time Branch