python - 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 有效。
解决方案
Heroku 在托管不和谐机器人方面出了名的糟糕,原因有很多。我建议使用不同的主机(AWS 提供一年的免费托管),因为制作 discord.py(Danny) 的主要人物之一已经说过不要使用它。
- 机器人也不是该平台的设计目的。Heroku 旨在提供 Web 服务器(如 Django、Flask 等)。这就是为什么他们给你一个域名并在他们的本地模拟器上打开一个端口。(引用自 discord.py discord 服务器)
如果 Heroku 在本地运行完美,它可能是导致您的错误的原因。
推荐阅读
- python - pandas.series.diff 奇怪的输出
- java - 在 Windows 上使用 Jar 文件启动 JMeter 时出现白色空白屏幕
- ruby-on-rails - 升级到 Rails 6 后,rspec-rails 在控制器测试中停止存根视图
- flutter - 消费者未使用 notifyListeners() 进行更新
- sql - 如何通过 VBA 运行 SQL 查询
- here-api - HERE TRAFFIC API TPEG,getmessage 加密
- xml - XSLT 2.0 for 循环一个与其他 XML 中的数据匹配的 XML 节点
- sql - Oracle sql 拆分行以填充 maxquantity
- r - 通过在 R 中对变量进行分组来有条件地更改值;基于两个数据帧中时间戳之间的差异时间的条件
- asp.net-core - 使用 CICD 管道为不同环境设置 AKS ConfigMap 数据