A Guide to Discord Bots

Hosting Your Bot

Finding A Host

A host is important because they are able to run your bot 24/7.
There are many hosts, but only a few of them are free.
The one I recommend is Glitch.com; we can also use Heroku, which has a free plan but also paid ones (and the free plan has hours/month limitations).

Hosting With Glitch.com

You can login through Github or Google, but your code can be made private.
You can start by "remixing" this project, and remove all of the code, then paste your own.

First, click your project name, change it as you want, change the description too, and don't forget to click the lock to make it private.

Anytime you edit a single character, Glitch will save it and restart your bot.
To avoid this, make a new file named watch.json and put this inside it:

{
  "install": {
    "include": [
      "^package\\.json$",
      "^\\.env$"
    ]
  },
  "restart": {
    "include": []
  },
  "throttle": 2000
}

It will now only restart if you edit package.json, watch.json or .env.

I strongly advise to use your IDE (Visual Studio Code, Atom, Sublime Text, ...) for tests and then post your code on Glitch!

Make sure to rename the .js file according to what you used (for me, index.js).
Don't forget to update package.json too.
You only need index.json (or any name you chose), package.json and env.

The content of env can only be seen by you, even if your code is public.
Now, you can go to env and link your token to a variable (example: token=your_bot_token_here).
Then, edit client.login() to client.login(process.env.token);.

If you need the console, click on 'Logs' above the file explorer.
Your bot will be online once you're done... for 10 minutes.
Which brings us to the next part:

Making Your Bot Alive 24/7

There are many websites for this, and you technically could make your bot do it, but it's safer to use an external source.
I recommend to use Uptime Robot.
This will ping your bot every 5 minutes so it never goes offline!

Make an account, verify your email, and login.
Click "Add New Monitor", put "Ping" as the type, give it any name you want ("MyDiscordBot"), and now for the url: your-project-name.glitch.me
Click "create", confirm and you're done!
Restart your bot by changing its code and it should be up and running :)

results matching ""

    No results matching ""