[Python] issue with sending messages automatically aiogram

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    i have created a telegram bot and now i want it to send a message to a user at exact time(for example, 11:10). here's how i wrote it:

    async def schedule_deadline():
    global USER_NAME
    aioschedule.every().day.at('11:25').do(check_deadlines_daily)
    while True:
    print(USER_NAME)
    await aioschedule.run_pending()
    await asyncio.sleep(10)


    async def main():
    dp.include_router(router)
    loop = asyncio.get_running_loop()
    loop.create_task(schedule_deadline())
    await dp.start_polling(bot)


    if __name__ == '__main__':
    asyncio.run(main())



    but the problem is that the code doesnt even reach def check_deadlines_daily. at time which is written in aioschedule.every().day.at('11:25') the exception occur:

    future: <Task finished name='Task-2' coro=<schedule_deadline() done, defined at C:\Users\asus\PycharmProjects\bot_v1\main.py:453> exception=TypeError('Passing coroutines is forbidden, use tasks explicitly.')>
    Traceback (most recent call last):
    File "C:\Users\asus\PycharmProjects\bot_v1\main.py", line 458, in schedule_deadline
    await aioschedule.run_pending()
    File "C:\Users\asus\PycharmProjects\bot_v1\.venv\Lib\site-packages\aioschedule\__init__.py", line 544, in run_pending
    await default_scheduler.run_pending()
    File "C:\Users\asus\PycharmProjects\bot_v1\.venv\Lib\site-packages\aioschedule\__init__.py", line 111, in run_pending
    return await asyncio.wait(jobs, *args, **kwargs)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\asus\AppData\Local\Programs\Python\Python312\Lib\asyncio\tasks.py", line 461, in wait
    raise TypeError("Passing coroutines is forbidden, use tasks explicitly.")
    TypeError: Passing coroutines is forbidden, use tasks explicitly.


    please, help me fix this problem

    Continue reading...

Compartilhe esta Página