I'm writing a discord bot using discord.py rewrite, and I want to run a function every day at a certain time. I'm not experienced with async functions at all and I can't figure out how to run one without using "await." This is only a piece of my code which is why some things may not be defined.
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())
Using the schedule.every().day.at("00:00").do()
function, I get this error when I put await send_channel()
in the paramaters of .do()
:
self.job_func = functools.partial(job_func, *args, **kwargs) TypeError: the first argument must be callable
But when I don't use await, and I just have send_channel()
as parameters, I get this error:
RuntimeWarning: coroutine 'send_channel' was never awaited
I'm not super good at programming so if someone could try to dumb it down for me that would be awesome.
Thanks