[Release] Discord To FiveM Bot


#1

Back at it again, with another Discord related resource…

This release contains a resource for a FX Server and the javascript for a Discord Bot.


Commands

cmdlist - Shows a list of commands
chkcon <SERVER> - Checks if the connection to the specified Server was successful
getclients <SERVER> - Gets the connected clients of the specified Server
send <SERVER> <MESSAGE> - Sends a chat message to the specified server
kick <SERVER> <SERVER_ID> <REASON> - Kicks a client from the specified server
ban <SERVER> <SERVER_ID> <REASON> - Bans a client from the specified server


Installation

These are the needed steps to install the bot


The FX Server part

This resource responses to the Bot requests

  1. Copy the folder DiscordToFiveM to your resources folder
  2. Open the config.lua and configure it
  3. Add start DiscordToFiveM to your server.cfg
  4. Add the following to your server.cfg
## DiscordToFiveM Bot Password
set DTF_Password "ENTER_A_PASSWORD_HERE"
  1. Replace ENTER_A_PASSWORD_HERE with a password and keep it a secret
  2. You will need this password later… Copy it and save it for later

The FX Server part is finished now, continue with the Botty part!


The Botty part

We are going to create the bot now

  1. Visit this site and create a new app
    2-1. Enter a name (Thats the the name the bot will have later)
    2-2. Add a description if you want to
    2-3. Add a app icon if you want to
  2. Click on Create App

A new page should load and at the top it should say Great Success! or so

If so, continue

  1. Scroll down and click on Create a Bot User and accept
  2. Make sure Public Bot is UNCHECKED

Now your app is a bot, we need two things now, so continue

  1. You will need the CLIENT ID later… Copy it and save it for later
  2. You will need the TOKEN later, to see it scroll down to the bot section and click on click to reveal… Copy it and save it for later

Thats it with the Botty part, continue with the Javascript part!


The Javascript part

Requirements: Node.js

The actual Script for the bot follows now, I am using Windows, so I won’t explain how to install Node.js on Linux. Please search for instructions online.

Node.js (WINDOWS ONLY)

  1. Visit this site
  2. Download the Windows Installer (32bit or 64bit depending on your OS)
  3. Install it

Actual Javascript

  1. Extract the folder DiscordToFiveM_JS somewhere on your system (Remember the path, we need it in the next steps)
  2. Open the folder
  3. Open the config.json
    3.1. Replace YOUR_TOKEN_HERE with the token you saved earlier
  4. Open the servers.json
    4.1. Replace the first YOUR_IP_HERE with the IP of your FX Server
    4.2. Replace the first YOUR_PORT_HERE with the port of your FX Server
    4.3. Replace the first YOUR_PASSWORD_HERE with the password you saved earlier
    4.4. Replace the first ANY_NAME_HERE with the name the Bot should have In-Game
    4.5. Repeat these steps for each FXServer you want to maintain with this bot, use the added example to add more servers
  5. Open the channels.json
    5.1. Add for each command a valid channel id (you can use the same for all)
  6. Open the DiscordToFiveM_JS Folder and enter cmd in the bar at the top (Example Video (5.2 MB)
    )
    6.1. Enter node bot.js in the command prompt

Thats it with the Javascript part, your bot is running and ready to be added into your Discord Server.

Continue with the Discord part!


The Discord part

On the finishing line…

Since the 2.0.0 update, you don't need these steps so continue at "Now we are going to add the bot to the server"

We have to create a role for the bot, so it just listens to one channel

  1. Create a new role in your server
  2. Call it however you want
  3. Forbid all permissions
  4. Save it

We have to create a channel the bot listens to

  1. Create a new channel in your server
  2. Call it however you want
  3. Make it private, so not everyone has access to it
  4. Click on Create Channel or so
  5. Open the CHANNEL Settings
  6. Open the Permissions Tab
  7. Add the new role to the roles
  8. Forbid all permissions except Read Messages, Send Messages, Manage messages and Read message history

Now we are going to add the bot to the server

  1. Enter the following in you browser and replace YOUR_CLIENT_ID_HERE with the Client ID you saved earlier
https://discordapp.com/oauth2/authorize?client_id=YOUR_CLIENT_ID_HERE&scope=bot
  1. Select your Server
  2. Click Authorize

Back at Discord you have to add the role to the bot

  1. Add the role you created earlier to the new added bot
  2. Test if everything works by entering !!cmdlist in the bot channel (The prefix may be different for you if you changed it in the config.json)

Thats it, you added the Bot to your server and it is running!



Changelog
  • [1.0.0]
    – Initial Release
  • [1.0.1]
    – Fixed the ‘Bad Request’ Error
    – Fixed ‘getclients’ printing ‘null’ if there are no clients
  • [1.1.0]
    – Added ‘chkcon’ as a command to check if the connection succeed
    – Added ‘ban’ as a command to ban player
    – Added a ‘lang.json’ to translate the discord messages
    – Added the option to send a chat message when a player gets kicked/banned
    – Added the option to change the name of the Bot In-Game
  • [2.0.0]
    – Added multiple Server support
    – Added separated Command-Enter & Command-Answer channels
    – Added a Kick/Ban Log channel
    – Added a language file for the FXServer resource
    – Improved the chkcon command

Troubleshooting

After entering a command the message disappears and nothing happens

  • Check if the IP is correct
  • Check if the port is correct
  • Check if the password is correct

After entering the command ‘/chkcon’ it say Unsuccessful

  • The server is offline
  • The password is incorrect

Anything else…

  • Reply in this topic
  • Provide as much information as possible

I would add pictures but there is not much I can screenshot…

Nothing to tell you anymore…

Here is the download:

DiscordToFiveMBot [2.0.0].rar (1.7 MB)

VirusTotal Scan


[Release] FiveM To Discord
#2

I was thinking about something like this last night. Nice Work buddy


#3

Looks Nice. Going to test when I’m free today.


#4

I’ve followed your steps and I’ve checked and double checked the config file. Everything is set correct (user/pass) but I keep getting a “Bad Request” and “Couldn’t Send the message to FiveM”. I’m using your other DiscordBot with no issues, but this one plug is not working. Firewall ports are open, node is running, the scripts is running. Any help you can offer would be great. Also, in the directions, you have the config file named “config.js” but in the package, you have it “config.json”.


#5

Finally admins can be lazy whilst still getting the job done!, nice release :rofl:


#6

hello! cmdlist is working but other commands ain’t working at all. when i type them ,they just disappear,
id checked the IP ,Ports,and passwords and ain’t still working


#7

I have the same problem with “Bad Request” and “Couldn’t Send the message to FiveM”.


#8

I will look into this, I probably fucked something up… Give me some time


#9

Updated to v1.0.1



  • Fixed the ‘Bad Request’ Error
  • Fixed ‘getclients’ printing ‘null’ if there are no clients


Download in the First Post!


#10

Awesome release! Look forward to using this.


#11

Fixed this too, thanks for pointing this out. It was wrong in the direction. :slight_smile:

Thank you :blush:


#12

Suggestions:

  • Add the ability to ban from game.
  • Make it so when a player does get kicked it streams to the in game chat saying they have been kicked and why.
  • Config to be able to change the name of the bot when using /send.

#13

Now work https://gyazo.com/ab613076f6b133c10f354399aa17ac8a


#14

I am happy it works now for you :slight_smile:


#15

hello im new to this im sorry what do i do at Run CMD and cd into the DiscordToFiveM_JS path


#16

The easiest way to achieve this is to open the folder DiscordToFiveM_JS, entering cmd in the top bar and pressing enter.


#17

The bot goes offline when i turn my pc off is that something that should happen or not? Or is a vps needed to run it 24/7?


#18

That’s normal, the bot runs on your computer. If you turn it off, the bot obviously turns off too.

To run it 24/7 you need a server or an energy efficient computer, which can run 24/7.

A Rasperry Pi should work too, I think.


#19

Ok thanks :slight_smile:


#20

Hey, God damn awesome bot!
Where can i edit the Discord responses if i want to translate them to another language?