Relays messages sent in Discord to a Garry's Mod server, and vice versa. It works by you hosting a Discord bot. This is needed to read messages and send player messages as webhooks. We can't use the Garry's Mod server to post to a webhook because Discord blocks post requests from Garry's Mod for some reason. The bot and server connect by the bot hosting a websocker server.
- On gmod server:
- Messages on the server that start with
!
,@
, or/
are hidden
- Messages on the server that start with
- On Discord
- If a message has more than 4 lines, the bot won't relay it to the server, and will instead react with ❌
- If a message is over 512 characters in length, it won't be sent to the server. Instead it'll react with ❌
- If the bot is online but the gmod server is not connected to the relay, all messages will be reacted with
⚠️
I've updated this code to function with modern versions of the dependencies. This is a reupload because I accidentally included personal information in a previous upload. I deleted that repo and fixed it here.
- Put
Bot - Nubs Discord Chat Relay
anywhere in your computer. - Install Node.js.
- You only need the LTS version, recommended for most users.
- At the time of writing this, I'm running version
v18.14.1
.
- Open
Command Prompt
and navigate to where you put the bot files. - If you have
package.json
, which is already included, you can just runnpm install
and skip the next 3 steps (#5, #6, #7). - Install Discord.js with
npm install discord.js
.- We need this to interact with the Discord API :^)
- At the time of writing this, I'm running version
14.11.0
.
- Install Websockets with
npm install ws
.- We need this to host a websocket server for the gmod server to connect to.
- At the time of writing this, I'm running version
8.5.0
.
- Install Axios with
npm install axios
.- We need this to fetch Steam avatars.
- At the time of writing this, I'm running version
1.4.0
.
- Open file explorer and go to where you put your bot, and find
config.js
. The file will have comments also walking you through filling out what you need to fill out. The next few steps (up to #17) also walk you through filling out the config. - Go to Discord Developer Portal and create a new application.
- Go to the bot section and create a new bot account.
- Copy the bot's token into
config.js
to the variableDiscordBotToken
. - Head down to
Privileged Gateway Intents
and checkMessage Content Intent
. - Set
ServerIP
to the IP of the gmod server. You may need to port forward or figure out your IP. These notes should help you determine what to do:- Note: If you're hosting the bot and gmod server on the same system, leave it as
localhost
. - Note: If you're hosting on the same network but different computer, you will need to use internal network IPs
- To get your internal IP address, open the Command Prompt and run command
ipconfig
. Copy your ipv4 address.
Example:IPv4 Address. . . . . . . . . . . : 10.0.0.127
->exports.ServerIP = "10.0.0.127";
- To get your internal IP address, open the Command Prompt and run command
- Note: If you're hosting on separate networks, you will need to use public IPs and port forward
PortNumber
on the device hosting the Discord bot. Every ISP is different in how to port forward, so I cannot help you with this.- If you change the
PortNumber
variable, keep in mind that the range is limited to 1024-65535. See IBM for details.
- If you change the
- Note: If you're hosting the bot and gmod server on the same system, leave it as
- Head to Steams Web API Key and create an API key for the bot.
- The domain can be anything. This will be used to get Steam avatars.
- If you don't want to use them, skip this step and the next step.
- Copy your API key into
config.js
to the variableSteamAPIKey
. - The
SteamAvatarRefreshTime
variable is how many minutes until a Steam avatar is refreshed. - The
LogConnections
variable will log any attempted connections to a text fileconnection_log.txt
. Make it false if you don't want them to be logged. - With this link, replace [Client ID] with your bot's ID (found in General Information of the Discord developer applications), and use it to invite your bot.
https://discord.com/api/oauth2/authorize?client_id=[Client ID]&permissions=536872000&scope=bot
- This link will only have permissions checked that the bot needs.
- Start the bot with
start.bat
.- This batch file has a very basic auto restart in the event the bot crashes for whatever reason. Otherwise this is unnecessary if you don't want it or want something better.
To just start it without automatic restarting, donode bot.js
- This batch file has a very basic auto restart in the event the bot crashes for whatever reason. Otherwise this is unnecessary if you don't want it or want something better.
- Find the channel you want to be used as the communication relay, and type
--setgmodchannel
. If succesful, the bot will react with ✅. From there, you should be good to go.
- gm_bromsock - Installation:
- Find the Builds directory, and find an appropriate dll file for the operating system your server runs on.
- In your server files, navigate to
garrysmod/lua/bin
. Thebin
folder likely doesn't exist, so create it and drop the dll file in there.
- Gmod Websockets - Installation
- Download the zip file and extract it to
garrysmod/addons
. - Note: If you're on a linux based server, you will need to make every folder name lowercase.
- Download the zip file and extract it to
- Drop
gmod_nubs_discord_chat_relay
intogarrysmod/addons
. - Navigate to
garrysmod/addons/gmod_nubs_discord_chat_relay/lua/ndc_config.lua
and change theBotIP
andPortNumber
variables to the IP address and port number of the Discord bot. The port number will have to be the same on both the gmod server and discord bot. - There are comments to help you fill out the rest of the server config.
- Restart the server.
- If you've installed this onto the server first, it will get lua errors from Websockets until you set up the bot.