AttributeError: 'NoneType' object has no attribute 'create_task'
File "main.py", line 40, in dp.loop.create_task(delay(30)) AttributeError: 'NoneType' object has no attribute 'create_task'
async def delay(wait):
while True:
await asyncio.sleep(wait)
now = datetime.utcnow()
await bot.send_message(724700370, f"{now}", disable_notification=True)
if __name__ == '__main__':
dp.loop.create_task(delay(30))
executor.start_polling(dp, skip_updates=True)
bot = Bot(token=cfg.API_TOKEN)
dp = Dispatcher(bot)
Ответы (1 шт):
Автор решения: c1vgk
→ Ссылка
Решил:
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.create_task(delay(10))
executor.start_polling(dp, skip_updates=True)