Discord-To-Roblox Ban bot

Discord To Roblox Ban Bot

Update as of 12/8/19

This source has been used by phenomenal games like Vehicle Simulator, and many other great games. A few months ago me and @Belzebass had decided to add on to Discord To Roblox Ban bot, to be able to have large games support this bot, without it bugging out and or rate limiting whilst still using these sources. If you wish to have this addition , download this lua file and add it to your Roblox game.

ban_system_kensizo_and_belzebass.lua (2.5 KB)

Please note you do have to change some areas of the glitch bot, screen shots provided:

Old;

New;

Please keep in mind there is some added code in there, for a personal test created.

Basically what needs to be changed, is where the bot is posting a request to your sheet.

The ban post request to change to:

axios.post("https://script.google.com/macros/s/" + scriptID + "?sheet=Global&key=" + args[1] + "&value=" + true + "&reason=" + reason + "&moderator=" + message.member.user.tag, {});

The unban post request to change to:

axios.post("https://script.google.com/macros/s/" + scriptID + "?sheet=Global&key=" + args[1] + "&value=" + false + "&reason=Unbanned" + "&moderator=" + message.member.user.tag, {});

You also need to add these to the spread sheet you have:

image

Please watch out for more updates to this bot, and possibly a version two. Thank you all for the constant support and suggestions, we really appreciate it. We hope you enjoy this optional addition!


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;

https://gyazo.com/dceadb9372c565f66fd8cba545860e38.gif

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;
https://gyazo.com/81f3769551c5f362340f4467ea5524ed.gif
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”

https://i.gyazo.com/2d652d9abe526443dae9441098101d40.mp4
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 (Discord Developer Portal) 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;

  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;
    Quotas for Google Services  |  Apps Script  |  Google Developers

  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

356 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.
27 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.

9 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.

5 Likes

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

4 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.

4 Likes

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)

5 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. Glitch: The friendly community where everyone builds the web

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.
https://gyazo.com/4d8afe2875f61064b2ac8808aa2cce25
Here is a thread from glitch explaining how to do it if you are still confused;

@Meta_data your suggestions are appreciated, and we used them. Thank you!

5 Likes

Will definitely be useful. Great work lads

2 Likes

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.

3 Likes

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.

1 Like

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:

3 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.

12 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.

8 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:

3 Likes