首页 > 解决方案 > Heroku 调度函数使用 Heroku Scheduler Python

问题描述

所以我正在使用 python.py API 开发一个不和谐的机器人,我试图让它每天使用 Heroku Scheduler 写一些东西,但我不能让它工作。主要问题是每个与 discord 交互的函数都需要是异步的,但不能在异步函数之外进行调用,如下所示:

async def hi():
   channel = bot.get_channel(int(general)) #get the general channel from the id
   await channel.send("Hello")

await hi() #not allowed (outside async func)
hi() #needs to be awaited

由于 Heroku Scheduler 需要提供运行整个脚本的作业(例如 python scheduler.py),因此我看不到使该功能正常工作的方法。因此,如果我删除 await 键盘,它显然不起作用。如果我删除了 async/await 关键字,它就不能与 discord 交互,因为它不是异步的,如果我将它保留在示例中,它会说我不能在异步函数之外调用 hi()。我该怎么做?提前致谢。

标签: pythonherokuasync-awaitdiscord.py-rewrite

解决方案


推荐阅读