如何获取正常运行时间机器人的 replit 链接?

How to get the replit link for uptime robot?

提问人:Prathamesh Bhatkar 提问时间:7/25/2023 更新时间:7/26/2023 访问量:177

问:

我制作了一个超级简单的 discord 机器人(用于学习跟踪会议) 我希望它 24/7 全天候运行

因此,从所有的谷歌搜索中, 我发现我可以在网站的帮助下做到这一点,为此,我需要我的 repl 的 URL/链接,格式应该是(我在某处找到的)uptime robothttp://REPL-NAME--USERNAME.repl.co

但问题是

我找不到我的 repl 的链接/URL

我的 repl 窗口视图

任何帮助将不胜感激(如果可能,请提供屏幕截图)🤗!!

我试图创建我自己的 URL,例如http://PythonStudyBotRepl--CodingCircle2.repl.co

Python discord.py Replit 正常运行时间

评论

0赞 boez 7/26/2023
你最终需要在你的 replit 中运行一个 Web 服务器
0赞 Prathamesh Bhatkar 7/26/2023
是的,我只是认为没有必要运行网络服务器,因为它是一个简单的机器人,但事实证明你需要这样做才能获得一个有效的链接

答:

1赞 QAEZZ 7/26/2023 #1

您需要使 replit 托管一个网站。
您可以通过制作 webserver.py 文件来实现此目的。

webserver.py

from flask import Flask # Make sure to install the flask package
from threading import Thread

app = Flask('')

@app.route('/') # The "main" page of the website. The root.
def home():
  return "Webserver OK, Discord Bot OK"

def run():
  app.run(host="0.0.0.0", port=8080)

def keep_alive():
  t = Thread(target=run) # We use threading so the function doesn't block the discord client from running.
  t.start()

# It's pretty simple, create a simple webserver using Flask so replit gives you a URL to use, when starting the webserver use threading so it doesn't block the rest of the code from running.

调用它,
(或主文件的名称,等等)
main.pybot.py

from webserver import keep_alive
# [...]
keep_alive()
client.run(TOKEN)