Garry's Mod

Garry's Mod

Not enough ratings
Setting up the Discord Bot Plugin
By timschumi
This guide describes how to set up my Discord Bridge plugin and a matching Bot in Discord.

Support requests in the comments will be ignored (and occasionally cleaned up).
   
Award
Favorite
Favorited
Unfavorite
Setting up a Discord Bot
Creating an Application

Open the Discord Developer Portal[discordapp.com]. You may have to log into Discord for that, if you aren't already.

Click on the blue "New Application" button in the top right corner. A pop-up window will open, asking for a name for the Application. The name that you put in can be anything that you like.



In the example picture, I named my Application "TTT Bot".

Before pressing the blue "Create" button, make sure to read the Terms of Service (if you are into that). After that, click "Create" to save your changes. You will be redirected to the overview page of the newly created App.

Adding a Bot user (and inviting it to your server)

When on the overview page for your Application, press on the "Bot" button on the left-side menu of the page.



You will find quite an empty page on the right side, containing a shiny blue "Add Bot" button. Click on it. It will ask for confirmation, so confirm it. Congratulations, your Application now has an attached Bot user, which is the thing that joins your server and actually does stuff.

Next, we'll have to allow the Bot to access the full member list (for looking up users by username). To do that, toggle the switch next to "Server Members Intent" and press "Save changes".



To invite the bot to your server, you will need the following Invite-Link template (I can't figure out how to make a preformatted text field, so you'll have to copy-paste the link maually):

https://discordapp.com/oauth2/authorize?&client_id=651731958660857871&scope=bot&permissions=4194304

At the moment, the URL still contains my example Bot's Client ID, but we will fix that in a minute. To do that, go back to the "General Information" tab and copy the "Client ID".



Fill that number into the URL, right behind "client_id=", replacing the number that is already there. DON'T modify the permissions, the number is just the encoded value for "Mute Members".

After you modified the link to match your Application, open it.

A page will open where Discord asks what guild to add the Application to. Select the guild from the drop-down list. Keep in mind that only the guilds show up, where you have the appropriate permissions for adding Bots. You don't need to change anything else, the needed permissions are already selected.



After you are done, press the blue "Authorize" button. You may need to answer a captcha, but I can't provide a guide for that :P

After you are done, you can close the window. A new bot should just have arrived in your guild.
Installing the Plugin
Installing the plugin is relatively easy. In general, you have two options.

Keep in mind that you shouldn't use both methods at the same time. Having two copies of the same addon installed at the same time may yield funny results.

Installing from the Workshop

Installing the plugin (and the support library) from the Workshop is the easiest method.
You will get automatic updates, and I'll update the Workshop copy relatively often (at least when something important happens).

https://gtm.steamproxy.vip/sharedfiles/filedetails/?id=2063714458
https://gtm.steamproxy.vip/sharedfiles/filedetails/?id=1908490932

Just click on "Subscribe" to automatically add both to your installed Addons.

For Servers, just add them into the Server Collection of Addons that are installed automatically.

Installing from GitHub

If you enjoy living on the cutting-edge (or manual updates), don't trust the Workshop, or you need a fix and I haven't bothered to upload it to the Workshop yet, this installation method is for you.

First, you'll have to download an archive of the plugin from the GitHub page[github.com]. You can obviously
git clone
the whole repository into the appropriate folder (which makes updating a bit easier), but that is rather for the more advanced users. If you are new to this and haven't heard of git before, just use the archive.



The archive contains a folder called "gmod-discord-master", which we will put into GMod's addon folder manually.

You can open GMod's base directory by right-clicking Garry's Mod in your Steam games list, pressing "Properties", switching to the "Local Files" tab and clicking on the "Browse Local Files" button. (Server admins, you'll figure something out.)



The folder will now be opened in your default file explorer, and should look a little something like this:



The screenshot has been made on Linux, with the 32-bit version of the game installed, so there might be some differences with the names of certain files. The basic directory structure (and all the files and folders we care about) are the same accross all platforms.

Now navigate into the
garrysmod/addons/
folder. Depending if you already have addons installed, this folder might already have files in it or it is completely empty. If it doesn't exist, just create it.

This is where you have to put the folder we extracted from the archive (or where you `git clone` the repository, if you used that approach). Make sure that you extract the whole folder, not just it's contents. After you are done, things should look like this:



The second picture shows the view of the folder inside the "addons" folder. Make sure that it isn't nested.

This has to be done for the support library[github.com] as well.

If you arrived here and everything looks OK, you should be done with installing the addon.
Setting up the Plugin
"The Console"

First of all, boot up Garry's Mod and assign a button to "Toggle developer console". We will need it.
Owners of a dedicated server will have to look for a different (often very obvious) way to access the developer console. In the future, I'll refer to it just as "the console".

Accessing the values

To be able to access the configuration values in the console, you will have to be connected to a server (if you are working with the Client, this means that you have to open a locally-hosted Singleplayer or Multiplayer game). This step is not needed if you are using a console for a dedicated server.

Setting values

Whenever I say "You have to set the console variable `variable_xyz` to the value `abc123`" (or something similiar), you have to set that through the console. In the case of the above sentence, you'd put in the following in the console and press Enter/Submit:



In most cases, setting those variables won't generate a response, it will just print the command that you put in into the console window. Also, most variables do have autocomplete, which helps you with less typing and checking if the variable actually exists.

The Bot token

The first value that we will put in is the Bot token. To do that, copy the "Token" from the "Bot" page of your application, and put it in the `discord_token` console variable.





As soon as you send the command to set the variable, the plugin will check whether the token is valid and print an information/error message (if you are in Singleplayer mode, you may need to unpause to make the message appear).

In my case (since you should never ever share your Bot token with anyone), I modified the token in this guide so that it is invalid, which is why the error message is printed.

The Guild ID

To obtain the Guild ID for your Server, we'll have to go into the Settings to enable "Developer Mode" first. To do that, press the "Settings" button in the bottom-left corner and go into the "Appearance" menu. At the end of the list, you will find a "Developer Mode" toogle which has to be turned on.

Now we can copy the "Guild ID" by right-clicking the Server in the server list and pressing "Copy ID".

Now, we can put that value into the `discord_guild` variable in the console (in my case, the Guild ID is "651737161917399042"):




Again, the plugin will check whether the Guild ID is accessible, and print a information message accordingly (this works only if the Token from the last step is valid).

Connecting a user

Now that we set everything up, it's time for us to test whether connecting a user works. Every user can do that by themselves through the chat, we just want to check functionality now.

To bind a Discord user to your Steam account, you can use the !discord chat command. When putting it in without any argument, it will print a help message containing all available options for identifying your user account:




For demonstration and simplicity, I'll just choose the "Small username" option:




(Don't be confused about the `STEAM_ID_PENDING` thing, my Steam just randomly decided that it doesn't have any internet connection. Usually it will display your numerical SteamID there.)

Hooray, it works! You should now have a working Discord-mute bot!
15 Comments
Aspect™ 6 Nov, 2022 @ 10:01am 
It doesn't accept my bot's token or discord server ID, any idea why that'd happen? I followed all the instructions in this guide.
werk 7 Aug, 2022 @ 3:54pm 
script errosr
timschumi  [author] 15 Feb, 2021 @ 3:08am 
As far as I am aware, yes.
☢️ W Y VΞ R Π 14 Feb, 2021 @ 7:48am 
Is this working safely in 2021?

gliv 14 Oct, 2020 @ 3:10am 
Cheers mate.
timschumi  [author] 13 Oct, 2020 @ 3:33pm 
The linked IDs are stored somewhere in the `garrysmod/data/` directory.

For the "access" thing: Discord made an API change and you now have to explicity enable access to the full user list in the _bot settings_ ("Server Members Intent"). I'll update the guide and add a notice to the error message.
gliv 13 Oct, 2020 @ 12:48pm 
Where is the data for the discord linking actually stored?

I can't link new accounts in-game anymore.

Just says "I do not have access to the user list of the Discord server!" even though it's been fine for a month. Still mutes people, just can't link new accounts.
timschumi  [author] 14 Sep, 2020 @ 1:18pm 
yes. and it has to be the correct DLL as well (correct OS and 32bit/64bit).
gliv 14 Sep, 2020 @ 1:05pm 
You just place the dll in the right directory right?
timschumi  [author] 14 Sep, 2020 @ 1:04pm 
The plugin should say in the log (might be a bit further up) if it correctly loaded CHTTP. If it doesn't, you made a mistake while installing the module.