Issue
I'm trying to send a message to a channel once a day at 02:39 using Schedule
and Threading
but I can't seem to get past
asyncio
"never awaited for".
My code:
@bot.event
async def on_ready():
t = Thread(target=timer)
t.start()
async def announceShop():
await bot.get_channel(00000000).send("test")
def timer():
while True:
schedule.run_pending()
time.sleep(60)
schedule.every().day.at("02:39").do(bot.loop.call_soon_threadsafe, announceShop)
Error:
RuntimeWarning: coroutine 'announceShop' was never awaited self._context.run(self._callback, *self._args)
How can I accomplish what I'm trying to do?
Solution
This solution works, but it is more of a "workaround".
This solution is using aiocron which is simular to cronjob on Linux.
pip3 install aiocron
import aiocron
@aiocron.crontab('2 3 * * *')
async def announceShop():
await bot.get_channel(00000000).send("test")
Answered By - Persson
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.