'Discord.py and Python Schedule, never awaited for?
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 1:[1]
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")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Persson |