C
C
cykacykablun2022-03-30 21:19:43
Python
cykacykablun, 2022-03-30 21:19:43

How to correctly fill in the aiogram telegram bot database array?

For an hour, I can’t pull out the user_id column from the test table for a loop

import sqlite3
from aiogram import types, Bot, Dispatcher, executor, types
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.builtin import CommandStart
from aiogram.contrib.fsm_storage.memory import MemoryStorage


con = sqlite3.connect('database.db')
cursor = con.cursor()
def db_table_val(user_id: int, user_name: str, user_surname: str, username: str):
  cursor.execute('INSERT INTO test (user_id, user_name, user_surname, username) VALUES (?, ?, ?, ?)', (user_id, user_name,user_surname, username))
  con.commit()

async def on_startup():
    cursor.execute('SELECT user_id FROM test')
    arr = []
    arr = cursor.fetchall()
    for user_id in arr:
        await bot.send_message(chat_id=user_id, text="Бот запущен!")
        await asyncio.sleep(1)
if __name__ == '__main__':
    executor.start_polling(dp, skip_updates = True, on_startup = on_startup)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elvis, 2022-03-30
@cykacykablun

await bot.send_message(chat_id=user_id[0], text="Бот запущен!")

and this is redundant
arr = []

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question