Run and stop the bot correctly

This commit is contained in:
LoRiot 2022-10-15 17:52:45 +03:00
parent 58bf722a97
commit a7d6626b12

19
bot.py
View file

@ -1,10 +1,25 @@
#!/usr/bin/python
from aiogram import executor
import logging
import os
import asyncio
from aiogram import Bot, Dispatcher
async def main():
"""TODO: Create and configure bot, connect to db"""
"""Configures and runs the bot, connects to the db"""
logging.basicConfig(level=logging.INFO)
API_TOKEN = os.getenv("API_TOKEN")
bot = Bot(API_TOKEN)
dp = Dispatcher(bot)
try:
await dp.start_polling()
finally:
await dp.storage.close()
await dp.storage.wait_closed()
await bot.session.close()
if __name__ == '__main__':