我该如何使用repl.it
对于我的 Python Discord Bot,并保持其 24/7 运行。
我以前用过keep_alive
但由于某种原因它停止工作。
有没有人有什么建议?
我不断在控制台中收到此错误:
172.18.0.1 - - [2019 年 2 月 16 日 11:25:10]“GET / HTTP/1.1”200 -
要让您的 repl.it 机器人 24/7 在线,您必须做 3 件事:
- 让机器人保持活力
- 添加后台任务
- 将您的 repl.it 机器人与正常运行时间机器人链接
1. 为了让我们的机器人保持活力,我们必须在 py 文件的头部添加以下代码:
from flask import Flask
from threading import Thread
app = Flask('')
@app.route('/')
def main():
return "Your Bot Is Ready"
def run():
app.run(host="0.0.0.0", port=8000)
def keep_alive():
server = Thread(target=run)
server.start()
2.添加后台任务:
status = cycle(['with Python','JetHub'])
@bot.event
async def on_ready():
change_status.start()
print("Your bot is ready")
@tasks.loop(seconds=10)
async def change_status():
await bot.change_presence(activity=discord.Game(next(status)))
3. 设置正常运行机器人 :
- 在正常运行时间机器人上创建一个帐户。
- After creating an account, go to the dashboard and click on Add new monitor
- select monitor type Http(s)
- then go to to ur project on repl.it and copy the url from the top of the console and paste it in url section of the monitor
- now set the monitoring interval to every 5 mins (so that it will ping the bot every 5 mins) and click on create monitor twice
- 就是这样……现在转到 repl.it 上的项目并点击“运行”按钮
如果你已经创建了你的不和谐机器人不和谐.js,我就此写了一篇中等文章:免费托管 Discord 机器人 24/7 在线!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)