Discord-To-Roblox Ban bot (100% Free)

Discord To Roblox Ban Bot

Hello! Today we present a Discord Bot, that is 100% open source and free to use. This bot and functions have been created by @Stratiz and @Kensizo . Us two teaming up, have decided to create this for the community. This bot features a ban, and unban command, and this stores on a google spreadsheet, so it is 100% free to use, and simple to set up. This mainly uses the platform glitch, to run the Discord bot for free. Now of course, you can easily run this bot on a Web Hosting, but we understand some users do not want to invest money into Web Hosting, which is completely fine, and this solution now exists.
Please do note, we did not fully create the Google Sheets section to this, and the Google Sheets section is just us modifying it and making it better, check this thread;
https://devforum.roblox.com/t/using-google-spreadsheets-as-a-database/12658
To get a better understanding of Google Sheets, we will also explain it in this post, and how to set up everything.

How does this work?

This Discord bot works by listening to the Prefix and checking if it is the ban or unban command. This bot and ban system works by UserId’s, you can easily make it usernames, by changing it up. Here is a representation of this bot in action;

And here is the output of this action;

The server on Roblox, then checks and sends a GetRequest to see if the player’s UserId is there, if it is , it checks if the BanValue ( or just value in this case ) is equal to true, if it is, the server kicks the player. To make the bans more instant, we added a while wait() do statement, and it then constantly checks if the player(s) in the server(s) userID’s are on the sheet. If it is on the sheet, and the value is equal to true, it kicks them. So this means it does not have to be the player joining every time, making it more convenient. If the Discord User then does unban UserId, it checks if that UserId is on the sheet, if it is, then the value turns to false, so then every time the player joins, or when the server constantly checks the sheet, it wont detect them as banned, as the value isn’t true. Here is how it looks when you unban a UserId;

And here is the output of this action;

How do I set up this system?


It’s actually pretty simple! Here are some step by step instructions, we did to make this work!

  1. Create your Google Spreadsheet.

To create a Google spreadsheet is simple, visit this site; https://docs.google.com/spreadsheets/u/0/

  1. Rename your Google spreadsheet to “Global”


3. Set up your game, and add this module;
DiscordToRobloxBanning.rbxm (1.7 KB)
Make sure the script and module are in ServerScriptService!
  1. (Hi its Stratiz now) Go to your Discord bot dev page (https://discordapp.com/developers/applications/) and press “New application”

  2. Once your app is created, press the “Bot” tab and press “Add bot”. Keep this page open, you’ll need it again in a later step.

  3. Sign up for glitch.com and check out our source code:

Our Source

From that page you should be able to branch it (AKA Remix).

  1. Enter the server.js tab and look for the var token.

  1. From the page in step 5, press copy on bot token (KEEP THIS SECRET) and paste it into the token variable. This token is what allows your bot to come to life.

  2. (Kensizo has joined the server) Basically, you now need to create a marco script. But before that, we must set up your values, to set up your values, add “key” and “value” in row 1.
    image

  3. We now need to freeze the row, to freeze the row, follow what this GIF does;

(FYI: When pressing freeze, Freeze 1 row, no more than 1.)

  1. Add the script, to do this again follow what this GIF does;

( A new page should’ve opened, once that has happened, do the following.)

  1. Change the script name to Database Macro.

  2. Paste this script into the Marco;

https://pastebin.com/q8LfTNNC

  1. After that, while on Database Marco, press File>Save All ( This will save all the progress)

  2. Press Run, this will run the script.

  3. Press Publish, and then press deploy as web app:

  1. Make sure you have the following settings for your script while publishing it;

  2. Publish the script, and copy the ScriptID in between https://script.google.com/macros/s/ and /exec , all you will need is this scriptID.

  3. Now in between the quotation marks, paste the ScriptID in there.
    image

Last step: Lets go back to the Glitch Discord bot, paste your script ID in the following;

That is how to set up the Discord-To-Roblox ban bot!

Make sure to let me and @Stratiz to know what we should add, also make sure to leave feedback, and let us know how you like the bot!
Things to note

  1. This Bot does not feature a moderator-only feature, so we highly recommend making a server either for only moderators, or adding an if statement to check if the Discord UserId’s match to a moderation list.

  2. You must have HTTP Requests turned on in Roblox.

  3. Sometimes, sending or requesting to much information will at one point be stopped, due to these limitations, the bigger your game is, the higher we recommend to have the while wait() statement in the script. Here is a list of the limitations;
    https://developers.google.com/apps-script/guides/services/quotas#current_limitations

  4. This is meant to be a project for you build off of, you can leave it as is, but it’s highly recommended that you learn from it and adjust the project to fit your needs.

  5. The only time data “won’t save” or will not register to the spread sheet, is when Google’s servers are down. ( Google’s servers are rarely down, so you most likely have nothing to worry about )

  6. To change the Prefix of the Discord bot, we’ve left a Prefix section, and you could change it from ; to anything whenever you need to.

  7. After requests, we’ve made the bot be able to handle errors.

  8. This bot does not feature an admin only system, but feel free to create a role and add this before the ban commands are put to play;

if (message.member.roles.some(role => role.name === 'ROLENAME')) {

(Also note to add a } near the end where an error appears if you added the role system)
What it should look like if you added the statement;

We hope you enjoy this project and hope you find a use for it! :wave:

Stratiz X Kensizo

122 Likes

Great work! I just wanted to suggest some things to further improve your project.

  1. The code below does not check if the message belongs to the current bot and uses your bot’s author id.
    if (message.author.id != 617782585594216448) { // Dont answer yourself.

//--You should use the code below and make sure you remove the closing mark from the current code to avoid errors.

    if (message.author.bot) return; 
  1. The ban/unban request may fail at any time for any reason which is why you should properly handle errors. No one wants to find out that the player they thought was banned is still playing the game.
10 Likes

Thanks for informing us about number1, it has been fixed and made more clear. I completely agree with number 2, but as we said;

This bot can be used as provided right now, and will work perfectly fine.

3 Likes

Great tutorial! This can definitely be taken a step further with additional tutorials on handling errors and adding additional features, such as integrating the Roblox API to ban a player using a username, but for beginners, this is great.

1 Like

Awesome! Proud to see you two doing something like this. Definitely going to use this! :grin:

3 Likes

Awesome! how long were you working on this?

2 Likes

This took us around 3 hours in total, to type out the thread, script the game side, collect the API’s, and create the Discord bot and get it working.

1 Like

Use ‘let’ instead of var, and add: client.on('error', console.error) or else your program will crash on an error.

Also would not recommend storing your bot token in the script itself, use a JSON file or alternatively a .env file + the dotenv module (official support for discord.js)

3 Likes

Just wanted to let you know, you should definitely use your own hosting service to run this sort of application, or run it on your own computer/Raspberry Pi etc.

All glitch projects are public, and therefore anyone can see your Discord Bot Token, and abuse it this way. IIRC, you have to pay? to have a private project - correct me if I’m wrong.
If you still wish to use glitch, you should definitely read this article, and apply it ASAP. https://glitch.com/help/env/

3 Likes

How do I get a custom domain? @JohnnyMorganz 0

Good morning! Glitch code is not visible as of today, you can open source your code, like we did. Glitch is safe, and @nice_clock a custom domain costs USD, glitch is completely free. To make your project private, or make your code invisible, there is a button at the project, you should press your profile, find the project, and then private it from there.

Here is a thread from glitch explaining how to do it if you are still confused;
https://glitch.com/help/privateproject/
@Meta_data your suggestions are appreciated, and we used them. Thank you!

2 Likes

Will definitely be useful. Great work lads

1 Like

Instead of using Google Sheets, try use enmap (const enmap = require(“enmap”)), arguably better than using google sheets and try append to a .json, but that’s just personal preference.

1 Like

Google sheets is free, and easy to use. This is why we chose it for this system. We didn’t want to over-complexity it , as we wanted it to be easy to use/improve for all users, new or advanced. Plus Google servers rarely crash.

Enmap is not free to use? I understand for the sake of interpreting and understanding code completely, but like I said, google sheets shouldn’t be used for serious projects, but at least everyone will understand the simplicity of google sheets.

correct me if i’m wrong

3 Likes

No Enmap is free to use, its just Google is easier to link up with Roblox than Enmap is, we left the system easily editable, for people like you who want to edit it and improve it for personal use! It can be used as-is right now, but we recommend to learn off of it and make it better. :smiley:

2 Likes

Wow, I was really wondering if this was possible at Roblox, thanks a lot and good work. :laughing:

1 Like

Google Sheets is easier, yes, but there’s also a limit of 2 million cells and it starts to overload once you get to a few hundred thousand cells. I’d reccomend using an actual database system like airtable, obvibase, or sodadb. Google Sheets isn’t that great if you plan to use it for a full game.

6 Likes

Google spreadsheets should not be used as a database and neither should other files which are not specifically intended to store data (.txt files, .json files etc…). Set up and use a proper database such as mongodb. It offers up to 512MB of data for free which is way more than enough for storing bans.

4 Likes

Completely agree with you guys , and what @Pseudorandomness said is true, 2 million cells is more than enough for ban data. All your guys suggestions are great, sure others who are confused and or need better ways to improve this will find it useful. :slight_smile: