如何使我的Discord.py bot 24/7我从vs代码编码
我已经从VS代码编码了一个Discord机器人。我如何保持 24/7 Active
I have coded a discord bot from VS code. How do I keep it 24/7 active
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有多种方法可以实现这一目标,但是没有看到我将要推断的实际源代码。
选项1-快速肮脏的解决方案
将代码放在无限环路中,并包括睡眠通话,以便您可以间隔运行机器人。这取决于您的需求,它可以每5分钟,每露秒钟等一次运行一次。
选项2-更好的解决方案
上面所述的相同解决方案,但在容器中运行Python脚本。这将使您的解决方案更加便携。
选项3-将其带到云上
一个强大的解决方案是将您的机器人部署到云中。最简单的云之一是Heroku,这将使您的应用程序更容易容忍。
There's multiple ways to achieve this, but without seeing the actual source code I am going to make some inferences.
Option 1 - Quick Dirty Solution
Place your code in an infinite loop and include a sleep call so you can run your bot in intervals. This depends on your need, it can run every 5 minutes, every dew seconds, etc. You can then execute the python script locally and it will run until you close the application or an error crashes the application.
Option 2 - A Little Better Solution
The same solution stated above, but run the python script within a container. This will make your solution more portable.
Option 3 - Take It To The Cloud
A robust solution would be to deploy your bot into the cloud. One of the easiest clouds to deploy to is heroku, which will make your application more fault tolerant.
您应该与Tim一起查看Tech的这一出色的教程,他在其中解释了如何免费在Heroku上24/7托管机器人。 https://www.youtube.com/watch?v
You should check out this great tutorial from Tech With Tim where he explains how to host a bot 24/7 on heroku for free. https://www.youtube.com/watch?v=BPvg9bndP1U
在repl.it上进行
restarter.py
文件在该文件中添加此代码:
和您的main.py文件
替换
client.run(os.getEnv('token''))
to toMake a
restarter.py
file on repl.itadd this code in that file:
and in your main.py file
replace
client.run(os.getenv('TOKEN'))
to