Q
Q
qwwwwwty2021-11-03 23:20:01
Python
qwwwwwty, 2021-11-03 23:20:01

How to display everything that is in the database (SQLite3) in one line, and not separately Python, Aiogram?

I have a code (function) that, with a certain command (!all_ID), displays everything (in our case, the username of users) in the chat on behalf of the bot. it is necessary that the bot displays all this in one line , and not separately . the bot displays as follows:
the first message from the bot: @username1
the second message from the bot next: @username2

It is required from the bot that it write like this, separated by commas :
one message from the bot: @username1 , @username2
here is the whole code:

@dp.message_handler(is_admin=True, commands=["all_ID"],commands_prefix="!/")
async def allid(message: types.Message):
    connect = sqlite3.connect('usersnames.dp')
    cursor = connect.cursor()
    select_all_rows = "SELECT * FROM 'username'"
    cursor.execute(select_all_rows)
    rows = cursor.fetchall()
    for row in rows:
        await dp.bot.send_message(message.chat.id, text = f'@{row[0]}')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2021-11-03
@qwwwwwty

collect a string in a loop. After send it once.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question