решил попробовать написать бота для ТГ, можете помочь разобраться что я не так сделал и решить проблему?
Код снизу это main.py
import logging
import asyncio
from aiogram import Bot, Dispatcher, F
from settings.config import TOKEN
from aiogram.filters import Command
from aiogram.types import ContentType, Message
from database.register import datebase
logging.basicConfig(level=logging.INFO)
bot = Bot(token=TOKEN)
dp = Dispatcher()
@dp.message(F.content_type == ContentType.TEXT)
async def start(message: Message):
user_id = message.from_user.id
username = message.from_user.username
name = await datebase().register(user_id, username)
print(name)
async def main():
await dp.start_polling(bot)
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print('Error')
Код снизу register.py
import time
from datetime import date
from aiomysql import Pool
from database.connection import db_pool
registration_date = date.today()
Working_hours = time.strftime("%H:%M:%S")
class datebase():
pool: Pool = db_pool
async def register(self, user_id, username):
async with self.pool.acquire() as conn:
async with conn.cursor() as cur:
result = await cur.execute("SELECT * FROM TGProfiles WHERE uid=%s", user_id)
row = await cur.fetchall()
if result == 0:
await cur.execute("INSERT INTO TGProfiles(uid, name, DateRegister) VALUES (%s, %s, %s)", (user_id, username, registration_date))
else:
return row
config.py
import asyncio
loop = asyncio.get_event_loop()
Код снизу connection.py
import asyncio
import aiomysql
loop = asyncio.get_event_loop()
async def connect(loop):
return await aiomysql.create_pool(
host='**.***.***.***',
port=3306,
user='Melic',
password='******',
db='info',
loop=loop,
autocommit=True
)
db_pool = loop.run_until_complete(connect(loop))
И снизу ошибка
RuntimeError: Task <Task pending name='Task-8' coro=<Dispatcher._process_update()
running at D:\Programmer\Uki-TG\.venv\lib\site-packages\aiogram\dispatcher\dispatcher.py:309> cb=[set.discard()]> got Future <Task pending name='Task-10' coro=<Pool._wakeup() running at D:\Programmer\Uki-TG\.venv\lib\site-packages\aiomysql\pool.py:203>> attached to a different loop
что делать?