1
votes

I am hosting my discord.js bot on my raspberry pi 4. Everything works fine but obviously on a electrical outage I want my bot to start up again by itself.

What I tried:

pm2 start index.js --watch --ignore-watch="node_modules" --name MeguBot
pm2 startup
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi
pm2 save

now when I reboot my rpi it and do the pm2 list command I get this: this (it shows my bot is started and running)

but the bot still stays offline on Discord

EDIT:

This is what I am getting in the error logs:

Error: getaddrinfo EAI_AGAIN discordapp.com discordapp.com:443
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
1
Are you sure the bot can connect from your pi when not run through PM2 (e.g. node index.js)?Chris Satchell
I just tried and it also works outside of pm2 by just executing the node index.js commandpai_7ce
Have you checked PM2's logs for any errors that occurred?Chris Satchell
From my understanding this is basically just trying to reconnect after a connection failure and is unable to, right?pai_7ce
You accidentally exposed your token in the linked upload, revoke it ASAP. Is the bot able to connect at all from your PI using PM2?Chris Satchell

1 Answers

0
votes

PM2 is good but Forever or Nodemon are better. Check them out here https://www.npmjs.com/package/nodemon https://www.npmjs.com/package/forever