[Discord] Bot Shutting Down


#1

Hello!

I’m hosting my Discord bot on Glitch, and I can’t seem to get it to stay on without me leaving the page open. I created the watch.json file as instructed on anidiots.guide with the following code:

{
“install”: {
“include”: [
"^package\.json$",
"^\.env$"
]
},
“restart”: {
“exclude”: [
"^public/",
"^dist/"
],
“include”: [
"\.js$",
"\.json"
]
},
“throttle”: 900000
}

But it still falls asleep/shuts down a few minutes after closing the page. Is there a way to fix this?


#2

Instances will sleep after 5 minutes if nothing has accessed an HTTP end point. You would need to use something like uptime robot to ping it. Keep in mind shutting down instances is partly how they keep this service free :wink: also discord bots tend to use a lot of disk space so you may run up against your disk quota pretty quickly.


#3

Here I made a small guide about discord bot hosting on glitch.
https://thelearneer.gitbooks.io/discord-js-glitch-hosting

This might help you out, and if there is any issues about the guide or any confusion, then you can ping me in discord as well.
https://discord.gg/DsPG6Af here.


Glitch restrictions?
#4

Are you sure that’s accurate? I’ve been using this exact example for my bot without any problem.


#5

Adding watch.json is not for keeping the project running, but instead for setting interval of project auto-restart.
So yeah the idiots-guide gitbook gives you some method to keep the bot running, but that will fail when the bots process shuts down, because you are making in-code http request, but the guide i linked above makes http request through external 3rd party website, so that keeps the project online no matter what.


#6

Ah, I see. Thank you for clearing that up.


#7

Awesome guide, thank you! (I also came from the anidiots guide and was so confused)


#8

Create an interval that makes a get request to your project every 5 minutes.

Here is an example.

const http = require('http');
const express = require('express');
const app = express();

app.listen(8080);
setInterval(() => {
http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
}, 300000);

Discord bot uptime
#9

the main reason we recommend using a third-party cron/uptime service in lieu of local settimeout calls is that local settimeouts will be reset if we, for some reason, have to restart the servers.


#10

I would do a 280s interval so that there is a little leeway and the app doesn’t shut down an instant before pinging itself. If you use uptime robot as well as this, then the app should never have more than five minutes downtime (and then only when the client is reinstantiated as per jennschiffer's comment).


#11

I did the steps of how to get it to work, but now everytime I am using a command, its answering 17 times…
Any help?

And btw, your discord invite link is expired.


#12

The only reason your bot would be replying would be either you have 17 instances of client running, or you have setup the message handler multiple times.
The best bet is to reset your bot’s token and then try to run the bot and see if it still answers 17 times.

and regarding discord invite link, I though that I might be helping people out with glitch stuffs around discord, especially getting too busy with life, and also because there is a great team here to help out with any issues. :smiley:


#13

Also check for any While/For loops that may be repeating the message


#14

use uptime bot or something else
to make your code run 24/7


#15

It would have been better if you had looked through all the replies in the thread.

Lately people are replying in random thread by just looking at the title and without looking at the replies.
(Not attacking you)

But I believe user should look through the post and all the replies before making a reply by just looking at the thread.

If you have a look into the replies, the issue was already solved.


#16

your gitbook website broke, it’s on the legacy one that I cannot login too.


#17

Its not broken, but instead taken down. Because the author of idoits-guide told me to take it down.
And also I am no-longer providing support for glitch over discord.
All because you can get awesome support out here.

So you can simply put your issue out as new thread (But first check if its already reported, solved and so on) and then you will get solution/answer real soon.