简体   繁体   中英

pm2 autostart discord.js bot won't connect again on reboot (raspberry pi)

I am hosting a discord.js bot on my raspberry pi 4. It connects flawlessly when I do it manually with pm2 start index.js Now the issue is when I tried to add it to autostart

pm2 autostart
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 restart I the process has started up, I get this when I type pm2 list在此处输入图片说明

but the bot will be offline on discord.

In the error logs I have this error repeating multiple times:

Error: getaddrinfo EAI_AGAIN discordapp.com discordapp.com:443
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)

However if I restart with pm2 restart 0 the discord bot will be online again.

It seems like the internet connection is not yet established when the bot starts. When you open raspi-config , go to Boot Options and check Wait for Network at Boot , the value should be "yes".

That way, the processes will be started when an internet connection is established.

In newer versions of raspi-config this option can be found in System Options , then Network at Boot .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM