[DOC] How to Create / Setup a Discord bot with RAT

Trekkan

JFF Administrator
Staff member
First, you need to create an application within Discord. You can use an existing app, but it is recommended you create a new app.

Go here: Discord API Docs for Bots and Developers

Log in, and click the "Create an application" box.

Type in an App name, it can be anything but it should be unique. This will also be the name that people will see your bot listed as in your server/channels.

Add anything to the description or app icon you want

Copy and paste the CLIENT ID somewhere

Click "Bot" on the left hand navigation

Click the "Add Bot" button

Click the "Yes do it" button on the popup that appears

Set the Username field to whatever you want to call your bot

Click Save Changes at the bottom of the screen

Click the "Click to Reveal Token" link next to the Token field under "App Bot User", copy and paste this somewhere

Make sure "Public Bot" is unchecked

"Requires OAUTH2 Code Grant" should also remain unchecked unless you know what you're doing.

Check the permissions you want your bot to have. Typically you'd only need "Send Messages" and "View Channels".

Once you've checked the permissions you want your bot to have, copy the value in "Permissions Integer" somewhere. Checking these boxes doesn't actually give your bot any permissions, it just generates the number. You use that number next.

You've now created your first bot and user. =)

Now you need to authorize this new bot to join your server.

Code:
https://discordapp.com/api/oauth2/authorize?client_id=YOURCLIENTID&scope=bot&permissions=YOURPERMISSIONSNUMBER
Edit the above URL before going there in a browser:

Replace YOURCLIENTID with the client ID you cut/pasted earlier.
Replace YOURPERMISSIONSNUMBER with the Permissions Number you cut/pasted earlier.

Go there in any browser. You only need to do this once, or if you somehow unauthorize the bot.

You will get a popup where you need to select the server you want to add the bot to in the dropdown and view the permissions this will grant. Now click the "Authorize" button.

Now, in RAT, click the Discord setup icon on the toolbar (the last icon as of this writing)

Check the Enable Bot box
Check the Auto Re/Connect box

If you want your bot to have a different name than your app, type that into the Bot Name box.
Paste the bot token you saved off earlier into the Bot Token box.

Click Test Connection

Assuming everything is ok, you'll get a popup stating so, and now the Bot Channel box will populate with the channels on your server. Select the channel you want your bot to reside in.

Click Save Settings
 
Last edited:

TOP-ic

New Member
I was able to add the bot only on this link:
Code:
https://discordapp.com/oauth2/authorize?&client_id=CLIENT_ID&scope=bot&permissions=0
 

Trekkan

JFF Administrator
Staff member
I was able to add the bot only on this link:
Code:
https://discordapp.com/oauth2/authorize?&client_id=CLIENT_ID&scope=bot&permissions=0
Interesting, I'll have to look up the permissions argument. Thanks!
 

Trekkan

JFF Administrator
Staff member
Seems as though someone else needed the permissions argument on there as well. Updated my first post with that info, thanks again!
 

djkrose

New Member
I just set it up on my server/channel and it works. Very nice!

Is it correkt that it is only a one-way link from game to Discord? Or can people from Disord somehow talk back into the game? Maybe even issue commands? If so, how?
 

Trekkan

JFF Administrator
Staff member
I just set it up on my server/channel and it works. Very nice!

Is it correkt that it is only a one-way link from game to Discord? Or can people from Disord somehow talk back into the game? Maybe even issue commands? If so, how?
Sure, you can reply, you'll need to add a new event for something like !SAY
Conditional: STARTSWITH:!say||CHECKDISCORDROLE:>=Discord Admins
Script: say "[{player_name}]: {0}"

Change the "Discord Admins" to a roll in Discord that you want to be able to use the chat command. Note that I think there is an issue using the default roles, so make a new one and set it to that. I'll work on that bug later.
 

Trekkan

JFF Administrator
Staff member
Also, you'd do the same thing for any commands you'd want, just set the access level they need in Discord, and do whatever you want them to do in the script.
 

TOP-ic

New Member
Good day! I understand that the above asked about feedback discord-->server.
I have configured the server --> discord and works great. But how to do to be able to write in discorde and displayed on the server, I don't understand. Prompt, please, in more detail. Thank you.
 

Trekkan

JFF Administrator
Staff member
Good day! I understand that the above asked about feedback discord-->server.
I have configured the server --> discord and works great. But how to do to be able to write in discorde and displayed on the server, I don't understand. Prompt, please, in more detail. Thank you.
I'm a bit unclear as you said you have it working from Server -> Discord, but that you want to write in Discord and show it on the server? That appears to be the same thing? The above response to djkrose does exactly that?

But to try and make that example more clear.

Create a new event, and set it with these parameters.

Type: Player Public Chat
Conditional: STARTSWITH:!say||CHECKDISCORDROLE:>=Discord Admins
Script: say "[{player_name}]: {0}"

Then, when you want to say something on the server, from discord, type:!say This is going to appear in the 7D2D game chat.

If you want your game chat to be displayed in Discord. Then edit the last event for Player Public Chat, it has an order of 9999 on it.

Add to the Script: .DSAY:<{player_name}> {player_chat}

That will display any chat the players type in the game, in Discord.

Those two options will cover both Game Server -> Discord and Discord -> Game Server.
 

TOP-ic

New Member
Sorry if not clear . Still the Google translator. )))
1. Established in the RAT that you wrote.
1.jpg
2. Write text in the programm Discord
2.jpg
3. The message appears in the tab Discord
3.jpg
4. But the chat is empty. (((
4.jpg

I missed something?

And again. I have duplicated messages. )))
5.jpg
 
Last edited:

Trekkan

JFF Administrator
Staff member
In Step 1, you have defined the command that RAT will listen for as !say

You also need to make sure that you either change the Discord role: Discord Admins, to a role that exists on your Discord server, or create that role and assign it to anyone you want to be able to chat in from Discord, into the 7D2D game.

So, if you want something in Discord to appear in the game chat, you need to prefix what you say with !say.

Example:

!say this is a test
!say Hello from Discord!
 

TOP-ic

New Member
Strange, but the connection is discord -> the server stopped working. In the settings did nothing. Two days worked, then stopped.
 

Trekkan

JFF Administrator
Staff member
Strange, but the connection is discord -> the server stopped working. In the settings did nothing. Two days worked, then stopped.
I've had one other report of this, I was told that rebooting was the only thing that allowed the connection to work again. If you can, please try that and let me know. It'll give me more information to work with when troubleshooting the issue.
 

TOP-ic

New Member
Unfortunately restarting the RAT, server, and discord did not fix the situation. The report does not come with discord to the server.
 

Trekkan

JFF Administrator
Staff member
I meant reboot the machine that RAT is running on. It shouldn't matter, but I'm told that fixed it for someone. So that's what I'm trying to test sinec I haven't encountered the issue.
 

Trekkan

JFF Administrator
Staff member
I'm able to reproduce many issues with this. It looks like the Discord service upgrade caused some issues with backward compatibility... so I need to dig into this a lot more. Basically, don't bother trying at the moment, its broken. I'll update as soon as I have something new.
 

Markezzz

New Member
I'm able to reproduce many issues with this. It looks like the Discord service upgrade caused some issues with backward compatibility... so I need to dig into this a lot more. Basically, don't bother trying at the moment, its broken. I'll update as soon as I have something new.
Hey Trekkan, is this feature working again or do you have to do some revisions?
 
Top