【发布时间】:2019-01-02 22:17:49
【问题描述】:
我正在使用 discord.py rewrite 编写一个不和谐机器人,我想每天在特定时间运行一个函数。我根本没有使用异步函数的经验,而且我不知道如何在不使用“await”的情况下运行一个函数。这只是我的一部分代码,这就是为什么有些东西可能没有定义的原因。
async def send_channel():
try:
await active_channel.send('daily text here')
except Exception:
active_channel_id = None
active_channel = None
async def timer():
while True:
schedule.run_pending()
await asyncio.sleep(3)
schedule.every().day.at("21:57").do(await send_channel())
@bot.event
async def on_ready():
print("Logged in as")
print(bot.user.name)
print(bot.user.id)
print("------")
bot.loop.create_task(timer())
使用schedule.every().day.at("00:00").do() 函数,当我将await send_channel() 放入.do() 的参数中时出现此错误:
self.job_func = functools.partial(job_func, *args, **kwargs) TypeError:第一个参数必须是可调用的
但是当我不使用等待时,我只有send_channel() 作为参数,我得到这个错误:
RuntimeWarning:从未等待协程“send_channel”
我不是特别擅长编程,所以如果有人可以尝试为我简化它,那就太棒了。
谢谢
【问题讨论】:
标签: python python-3.x async-await schedule discord.py-rewrite