【问题标题】:JavaScript discord bot keeps going offline with keep aliveJavaScript discord bot 通过保持活动状态不断离线
【发布时间】:2022-08-23 22:31:33
【问题描述】:
我有一个 Javascript discord bot,它越来越大,问题是每次我关闭我的 replit。大约 30 分钟后,我的机器人就离线了。
我在我的 keep_alive.js 文件中使用此代码
http.createServer(function (req, res) {
res.write(\"Online:)\");
res.end();
}).listen(8080);```
//I have this in index.js: `const keep_alive = require(\'./keep_alive.js\')`
标签:
javascript
discord
bots
【解决方案1】:
我找到并使用(而且是免费的)的最佳解决方案是 pm2。它根本不需要您的文件中的代码
https://pm2.keymetrics.io/
npm i pm2 -g
// navigate to the folder with your main bot.js file (in this example it is called index.js)
pm2 start index.js
// followed by
pm2 save
// Optionally you can monitor the whole server as well with
pm2-server-monit
还带有一个免费的仪表板
【解决方案2】:
如果你使用 replit 或类似的东西,你可以使用刷新来保持机器人在线。