首页 > 解决方案 > python脚本无法在heroku上托管的其他python脚本中调用fn

问题描述

我使用 Python 制作了一个 Discord Bot,并使用内置的 Git 命令在 Heroku 上托管了它。它运行主脚本,即 DiscordBot.py,该脚本从 topGainer.py 调用另一个 fn topGainer

当我在我的系统上本地运行 DiscordBot.py 时,机器人功能完美,但在 Heroku 上它无法调用 topGainer .py 函数 topGainer 返回一个使用 Tabulate 制作的列表

这是不和谐机器人的代码

if message.author == client.user:
    return

if message.content.startswith('$gainer'):
    tg=topGainer()
    await message.channel.send(tg)
    
if message.content.startswith('$loser'):
    tl=topLoser()
    await message.channel.send(tl)
    
if message.content.startswith('$get'):
    scrip = msg.split("$get ",1)[1]
    info=basic(scrip)
    await message.channel.send(info)
    
if message.content.startswith('$AnotherFunction'):
    await message.channel.send('Coming Soon :')

同样在 Heroku Procfile 我有worker: python DiscordBot.py

在 heroku 上,此代码确实登录了 discord 机器人,并且函数 $AnotherFunction 有效。

标签: pythonherokudiscorddiscord.py

解决方案


Heroku 在托管不和谐机器人方面出了名的糟糕,原因有很多。我建议使用不同的主机(AWS 提供一年的免费托管),因为制作 discord.py(Danny) 的主要人物之一已经说过不要使用它。为什么 Herkou 对不和谐机器人不利

  • 机器人也不是该平台的设计目的。Heroku 旨在提供 Web 服务器(如 Django、Flask 等)。这就是为什么他们给你一个域名并在他们的本地模拟器上打开一个端口。(引用自 discord.py discord 服务器)

如果 Heroku 在本地运行完美,它可能是导致您的错误的原因。


推荐阅读