【发布时间】:2021-03-31 04:41:24
【问题描述】:
async def on_ready():
print('We have logged in as {0.user}'.format(client))
schedule.every(5).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(1)
async def job():
print("I'm working...")
channel = client.get_channel(651895929426673704)
await channel.send('hello')
因此我收到错误“从未等待协程'job' self._run_job(job)”,但是无论我添加它,我总是得到“对象函数不能在'await'表达式中使用”有人可以吗请告诉我我做错了什么或者我必须把它放在哪里?
【问题讨论】:
-
看起来
schedule不是一个异步库 -
@Grismar 不,它来自github.com/dbader/schedule
-
不要使用
time.sleep这将停止你的整个代码。使用await asyncio.sleep(1)仅休眠该功能。另外看看discord.ext.tasks
标签: python async-await discord discord.py