So I'm hosting my discord bot on Repl.it with the hacker plan and its on the always on mode and for the most part, the bot is online 24/7. However, I've started to notice weekly / after a couple days of being online, the Discord bot randomly goes offline. There are no errors or issues in the Repl that are logged when it goes offline and I'm unable to bring it back even after restarting the Repl.
The only solution I'm able to get is forking the Repl.it and then rerunning the entire system. After I do that, the bot comes back online. Is there any reason or issue with Repl.it that might explain this or why it comes back online after I fork the Repl?
TL;DR: This post
You can add another file named server.js
:
const express = require('express');
const server = express();
server.all('/', (req, res)=>{
res.send('Your bot is alive!')
})
function keepAlive(){
server.listen(3000, ()=>{console.log("Server is Ready!")});
}
module.exports = keepAlive;
Notice how you can see a website window in your repl.
Now, reference the keepAlive
function in your index.js (or whichever file you use for your bot to work):
const keepAlive = require('./server');
And use it just before you login your token:
keepAlive();
client.login("TOKEN GOES HERE")
Then, you sign up an account on uptimerobot. It pings your bot for a chosen interval.
Follow the numbers:
https://i.sstatic.net/qXIvb.png (Sorry for the inconvenience, I don't have 10 reputations yet)
And you're done!