【问题标题】:Heroku Discord Bot Offline When Deployed?Heroku Discord Bot 部署时离线?
【发布时间】:2021-05-13 20:51:37
【问题描述】:

我目前正在使用 Python 创建一个 Discord 机器人——特别是通过 JetBrains 的 PyCharms IDE。我使用 PyCharm 作为 IDE 的问题是没有集成 Heroku,使用带有 Github 的控制台命令是所有噩梦的噩梦。

我在 github 上发布了我的代码,该应用程序通过 Heroku 成功部署,但该应用程序处于脱机状态。我到处检查过,没有一个解决方案适合我。

这是我目前的文件及其内容:

main.py

import discord
from urllib.request import urlopen
from discord.ext import commands

bot = commands.Bot(command_prefix='!')

token = "***********************"
client = discord.Client()
URL = "https://www.surrenderat20.net/search/label/PBE/"
page = urlopen(URL)
soup = BeautifulSoup(page, 'html.parser')
pbe_titles = soup.find_all('h1', attrs={'class': 'news-title'})
links = []

for tag in pbe_titles:
    for anchor in tag.find_all('a'):
        links.append(tag.text.strip())
        links.append(anchor['href'])
output = '\n'.join(str(line) for line in links[:2])
print(output)


@bot.command(name='pbe')
async def peebeeee(ctx):
    response = output
    await ctx.send(response)

bot.run(token)

我正在关闭我的令牌代码。如果我有兴趣分享代码,我会创建一个 .env,但 .env 在 Pycharm 中似乎效果不佳。

Procfile: worker: python bot/main.py 要求.txt: discord.py 运行时.txt: python-3.8.7

我当前的 github 的结构使得列出的所有文件都在主页上,包括文件夹:包含 main.py 的 bot ** 我将 Git 列为私有 atm

如果有人能解释一下为什么我的不和谐机器人即使 Heroku 成功部署它也不会保持在线,那就太好了。谢谢。

【问题讨论】:

  • worker 更改为简单的worker: python main.py。此外,如果您发现 Heroku 命令在您的 IDE 上是一场噩梦,您可以做的是将您的 GitHub 存储库连接到 Heroku 上的应用程序,这样每次您将代码推送到远程存储库时,它都会自动部署到您的Heroku 应用程序。
  • 即使我的 main.py 位于 repo 中名为“bot”的文件夹中,这也能正常工作吗?
  • 哦,我还以为你说主页上列出了所有文件
  • 我唯一能想到的其他事情就是摆脱你的Runtime.txt 文件,因为我没有那个文件,而且我的机器人在 Heroku 上工作得很好。另一件事可能是确保您拥有所有必需的构建包,尤其是heroku/python 构建包。最后,您可能需要在 Requirements.txt 中添加更多项目。例如,我有git+https://github.com/Rapptz/discord.pyPyNaCl==1.3.0dnspython==1.16.0pandasasync-timeout==3.0.1
  • 嗯。我会添加这些并试一试。 requirements.txt 文件名是否区分大小写?不幸的是,我真的很困惑。

标签: python heroku discord.py bots


【解决方案1】:

这个 repo 可能会有所帮助,因为它提供了一些关于创建机器人并将其托管在 Heroku 上的见解。

我能想到的唯一一件你可能没有做的事情就是你没有打开工人:

在“资源”下,执行以下操作: 单击“铅笔”图标。 将工作人员从关闭切换到开启。 点击“确认”以完成决定。

【讨论】:

    猜你喜欢
    • 2020-12-21
    • 2019-12-19
    • 2022-01-22
    • 1970-01-01
    • 2020-11-24
    • 2018-06-06
    • 2020-01-22
    • 2020-07-16
    • 2020-11-25
    相关资源
    最近更新 更多