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:
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 also discord bots tend to use a lot of disk space so you may run up against your disk quota pretty quickly.
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.
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.
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.
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).
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.
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.
I have a follow up question to your guide above. I read through post and didn’t see anything related. I followed your steps to the letter, and my bot seems to be timing out[1]? In discord, bot works just fine[2], but when i go to the bot’s page on glitch https:// tigglesbot.glitch. me/ it appears to just time out, and nothing seems to load onto the page. Also, it is telling me that there must be an error in my code or something, which also does not seem to be the case when I check my logs[3]. Any help here? End goal is to just keep this bot online without me having to run nodejs locally every time.
You’re not listening on a port and haven’t defined any routes in your app. It will continue to show the loading icon until that’s resolved. Try adding the following toward the top of index.js
var express = require('express');
var app = express();
app.get("/", (request, response) => {
response.sendStatus(200);
});
app.listen(process.env.PORT);
When I try to add this code to my project at the top of bot.js I get the following error:
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at Server.setupListenHandle [as _listen2] (net.js:1355:14)
at listenInCluster (net.js:1396:12)
at Server.listen (net.js:1480:7)
at Function.listen (/rbd/pnpm-volume/c8e7a0c5-ef98-4267-b4c0-3c915c8f695c/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/application.js:618:24)
at Object. (/app/bot.js:187:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
How are you establishing that your bot ‘completely shuts down’? Botkit Slack bots use webhooks so it isn’t necessary to keep the bot awake as it should wake in response to an incoming request. Nevertheless, your project is responding properly to a http request to lying-bus.glich.me, so it being hit by UptimeRobot would be enough to prevent it from sleeping.
At first uptimerobot was not working but I decided to choose ‘port’ instead of ‘http’ and then chose the ‘https’ port and kept everything else what was said by @shindakun , and guess what it worked like magic. Thanks to discord.js, Glitch and uptimerobot for this successful project.