Discord bot goes offline after several hours


So this is incredibly annoying to test because I have to wait several hours to even see what’s happening, but basically after several hours of running perfectly fine my discord bot’s account goes offline and no longer responds to chat messages. When it does this I have to restart the bot from the server. It may be connected to inactivity on the discord servers, I’m not sure as I haven’t identified a pattern yet, however it usually happens at night when I am sleeping so it’s quite the hassle.

It’s worth noting that I am keeping the server awake both from my code and using uptime robot. Uptime robot says it’s live and the server console when the downtime happens is reporting pings, so the server itself isn’t down, just the connection to discord.

If anybody has experienced this issue and resolved it, or thinks they are able to help, it would be VERY MUCH appreciated, because I’m using glitch so I can host this bot 24/7 like I’m sure many people do, if this can’t be resolved then my hopes of making a discord bot are basically dead. Thanks in advance.


I haven’t heard of bots timing out due to inactivity, but if it’s the case you could include a bot command in your uptime robot ping, so that you’re keeping the bot active on the Discord side too. Failing that, I’d try adding more logging around the commands to make sure it’s not some unreported error causing the problem.


How would I add a bot command to the uptime robot ping?


Actually would I even need uptime robot for that? Couldn’t I just periodically send a message?


You could, but how are you going to periodically send the message? My point is that you could use Uptime Robot to do that - put a Discord API call into the route you have defined for uptime robot and it’d both keep the Glitch project awake and send the message to Discord keeping that functioning too.


Okay so I visited my bot’s actual webpage instead of just the editor, it appears it’s going to sleep due to inactivity? How do I remedy this, I thought that’s what uptime robot was for?


It is, so you must not have it setup quite right. Let us know the project name and we’ll take a look. If your project is private, either make it public temporarily or DM me a join link so we can view the code. Thanks.


The setup actually looks ok. You don’t need to ping the bot with setInterval and use uptime robot - it’s redundant and setInterval as a method of keeping a project awake isn’t reliable. You also don’t need to publicly expose the watch.json file. So I fixed both of those little things up. But if your project is going to sleep, so long as uptime robot’s ping time is set to 5 minutes, then you should look into adding more logging to your app and seeing if there’s an unhandled error taking your bot offline instead.


What error could it possibly be? Normally when there’s an error it would just automatically restart, but it just randomly dies when nobody is interacting with it. Uptime robot says it’s still up. Going to the webpage says it’s asleep. I’m more confused than anything.


That’s what the extra logging will tell you. If uptime robot is saying the site’s up, then it means it’s getting a 200 response from the page so it isn’t a fault from Glitch.


So I haven’t done any additional logging, however since you removed the redundant method of keeping the project alive and I set up uptime robot again I am getting new results that I am much happier with:

While it would be nice if I could cut down the very small durations where it’s down, it’s not entirely necessary, so if you can’t help with that it’s understandable. However if you can it would be much appreciated, it’s so close to perfection.


I’d see how it goes over the next couple of days. We’ve had some server issues today, which might have contributed to the little bits of downtime. Otherwise it’d be handy to cross-reference the downtime with particular bot commands as it could be a memory issue.


The bot actually wasn’t used at all during this timeframe as far as I know


check this example https://glitch.com/edit/#!/discord-js-ex

bot will run 24/7


Alright, now these are results I like. Thanks for all the help @Gareth