Free Discord Bot Hosting!!


SUBMITTED BY: 0Z3R0

DATE: May 17, 2021, 11:57 a.m.

UPDATED: May 17, 2021, 12:17 p.m.

FORMAT: Text only

SIZE: 4.2 kB

HITS: 24345

  1. Prerequisites:
  2. 1. A Discord bot that is already written. This guide only covers hosting, not coding. You obviously need to have the source code and should be able to run it locally without any problems.
  3. 2. Some basic problem-solving problems if you encounter any simple errors (e.g: A popup that asks you to allow cookies on the website, verifying email, etc.)
  4. This will allow you to host a Discord bot for free 24/7 without needing to have your computer open / connected to the internet. You will also be notified if the bot goes offline. If you have any problems, DM me on Discord for help (0Z3R0#1234).
  5. Part 1: Importing the Code to Replit.com
  6. Step 1: Go to http://replit.com/ and create an account / sign in.
  7. Step 2: After you have created an account, go to https://replit.com/~
  8. Step 3: Click on "+ New repl" at the top left corner.
  9. Step 4: Select the language that your bot is written in. Name your Repl something that you can easily remember. Then click on "Create repl"
  10. Step 5: You will be redirected to the online IDE.
  11. Step 6: If your code is only in one file, you can just copy paste the code into the IDE. If it has multiple files or folders, click on "Add File" to the right of "Files" on the top left corner (make sure the top-most tab is selected on the most left)
  12. Step 6: Click on the green "Run" button, and make sure your bot can run without any errors.
  13. Part 2: Hiding the Token
  14. Step 1: All Repls are public (unless you upgrade to a premium plan) meaning anyone can access the source code and your token if you have it hard-coded there. You have to set an environment secret which is hidden to all users other than you.
  15. Step 2: Click on the Lock icon on the left side (above the cog, below a cube)
  16. Step 3: Set the key to "DISCORD_TOKEN" and value to your bot's actual token (no quotes, only the XXXX.XXXX_XXXX token value).
  17. Step 4: Click on "Add new secret"
  18. Step 5: You should now see on the bottom of the left side "Use secrets in the repl" and under that a dropdown currently showing DISCORD TOKEN and a line of code under than and a "Insert ->" button. Click on the top of your code and click on the insert button. The line should now appear in your code.
  19. Step 6: The variable mySecret is the name by default and you can use that variable to replace your token and keep it safe. Click on run and confirm that the bot still works.
  20. Part 3: Creating the Web Application
  21. Step 1: This will depend on the language of your bot. For Node.js, it would look something like this.
  22. CODE
  23. //Keep Alive
  24. const express = require('express');
  25. const app = express();
  26. const port = 3000;
  27. app.get('/', (req, res) => res.send('Bot is alive!'));
  28. app.listen(port, () => console.log(`Example app listening at http://localhost:`));
  29. Each language will vary. Just google "Replit *language* web server" and you will find results on how to do this.
  30. Step 2: Now, click on the Run button again. You should see the right side of the screen split into two sections. The top should be an embedded webpage. Copy the URL, this is very important. The URL should be in the format https://ReplName.YourUsername.repl.co. You should be able to enter the URL in a new tab and see some text (in the example above with Node.js, "Bot is alive!".
  31. Part 4: Keeping the Bot Alive
  32. Step 1: Replit automatically stops a project after 1 hour of no HTTP Requests. We can fix this.
  33. Step 2: Go to https://uptimerobot.com/ and "Register for FREE".
  34. Step 3: After you have signed up (you may need to confirm email), navigate to the Dashboard and click on "+ Add New Monitor".
  35. Step 4: Set the Monitor Type to HTTP(s), set the URL to the url from Part 3 Step 2. Set the Monitoring Interval to 5 minutes (to monitor it more frequently, you have to upgrade to a premium subscription). I highly recommend ticking your email in the "Alert Contacts to Notify" section as you'll know if the bot is offline or has some errors.
  36. Summary: The 4 parts to this guide covers importing your code to Replit, hiding the token so it's private, creating the web application so the Repl can stay alive, and actually keeping it alive.
  37. If you have any problems or questions, DM me on Discord for help (0Z3R0#1234).

comments powered by Disqus