JavaScript discord bot keeps going offline with keep alive

Viewed 388

I have a Javascript discord bot, and it is getting bigger and bigger, the problem is that every time I close my replit. In about 30 minutes my bot just goes offline. I use this code in my keep_alive.js file


http.createServer(function (req, res) {
  res.write("Online:)");
  res.end();
}).listen(8080);```

//I have this in index.js: `const keep_alive = require('./keep_alive.js')`

 
2 Answers

The best solution that I have found and use (and it is free) is pm2. It requires no code in your file at all

https://pm2.keymetrics.io/

npm i pm2 -g

// navigate to the folder with your main bot.js file (in this example it is called index.js)

pm2 start index.js

// followed by

pm2 save

// Optionally you can monitor the whole server as well with

pm2-server-monit

Comes with a free dashboard as well

You could use freshping to keep the bot online if you use replit or something like that. You just need this like website you can monitor.

Related