python 脚本无法在 heroku 上托管的其他 python 脚本中调用 fn
python script unable to call fn in other python scripts hosted on heroku
我使用 Python 制作了一个 Discord Bot,并使用内置的 Git 命令将其托管在 Heroku 上。它 运行 是主脚本,即 DiscordBot.py,此脚本从 topGainer.py
调用另一个 fn topGainer
当我 运行 DiscordBot.py 在我的本地系统上时,机器人功能完美,但在 Heroku 上它无法调用 topGainer .py 函数 topGainer returns 使用 Tabulate 制作的列表
这是 discord bot 的代码
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 bot 并且函数 $AnotherFunction 有效。
Heroku 在托管不和谐机器人方面出了名的糟糕,原因有很多。我建议使用不同的主机(AWS 提供一年的免费托管),因为 discord.py(Danny) 的主要负责人之一说不要使用它。
- Also Bots are not what the platform is designed for. Heroku is designed to provide web servers (like Django, Flask, etc). This is why they give you a domain name and open a port on their local emulator. (Referenced from the discord.py discord server)
如果 Heroku 在本地运行完美,则可能是导致您出错的原因。
我使用 Python 制作了一个 Discord Bot,并使用内置的 Git 命令将其托管在 Heroku 上。它 运行 是主脚本,即 DiscordBot.py,此脚本从 topGainer.py
调用另一个 fn topGainer当我 运行 DiscordBot.py 在我的本地系统上时,机器人功能完美,但在 Heroku 上它无法调用 topGainer .py 函数 topGainer returns 使用 Tabulate 制作的列表
这是 discord bot 的代码
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 bot 并且函数 $AnotherFunction 有效。
Heroku 在托管不和谐机器人方面出了名的糟糕,原因有很多。我建议使用不同的主机(AWS 提供一年的免费托管),因为 discord.py(Danny) 的主要负责人之一说不要使用它。
- Also Bots are not what the platform is designed for. Heroku is designed to provide web servers (like Django, Flask, etc). This is why they give you a domain name and open a port on their local emulator. (Referenced from the discord.py discord server)
如果 Heroku 在本地运行完美,则可能是导致您出错的原因。