My Profile Photo

Bencey's Blog


Informing the world about the application of Technology.
If you are looking for Tier III Technologies click the button below


Bot hosting on glitch.com

Hosting your bot on glitch

Thanks h0730#2470 for the blog post suggestion

Hey, If you need to host your bot and dont have any devices/Unable to host it on your devices one of the ways I hosted my bot was using glitch. You are able to goto the website by clicking Here. The first thing you will need to do is create an account or sign in then you will need to create a project (Copy all your bot files into the project) Now your bot will run but when you exit out of the browser the bot will stop running. We don’t want that now do we, So we will need to make some minor adjustments to your code

Create a file called watch.json and copy the following code

  "install": {
    "include": [
      "^package\\.json$",
      "^\\.env$"
    ]
  },
  "restart": {
    "exclude": [
      "^public/",
      "^dist/"
    ],
    "include": [
      "\\.js$",
      "\\.json"
    ]
  },
  "throttle": 900000
}
  1. Add the following code to your index.js file (Or whatever your main file is)
    const http = require('http');
    const express = require('express');
    const app = express();
    app.get("/", (request, response) => {
      console.log(Date.now() + " Ping Received");
      response.sendStatus(200);
    });
    app.listen(process.env.PORT);
    setInterval(() => {
      http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
    }, 280000); 
    

    So know your bot will be running but the only downside is that every 12 hours the bot will shut off so to fix that you need to go back to the project file and refresh the page. This is a pain I know but it’s better than nothing. To make sure no one gets your token I would suggest locking your project by clicking the lock in the top left. or you can put your token in the ENV file by putting the following code in the ENV file TOKEN=’xxx’ And then going to your index file and where the bot logins in using your token you replace the token with process.env.TOKEN so your code should now look like bot.login(process.env.TOKEN); Then remove your token from your config if its there. And now even if people have the link to view your code they cannot see your token as only the project owner can see .env files

Thanks for reading

Bencey