N
N
Nikolai Neizvestny2020-04-24 21:14:28
Python
Nikolai Neizvestny, 2020-04-24 21:14:28

Mailing to all id, sends so far only to the first in the database?

Tell me if there is a base.db base , user ids
are recorded in it,
I need to organize a mailing list for all users of the bot, but for some reason it does not display all ids, but only the first one, why?

def all_id():
    conn = sqlite3.connect('base.db')
    cursor = conn.cursor()
    cursor.execute('SELECT id FROM users')
    words = cursor.fetchall()
    conn.commit()
    cursor.close()
    conn.close()
    return words[0]

and here is how I send it to all users
elif mail == True:
        mail = False
        text = base_work.all_id()
        bot.send_message(message.chat.id, 'В течении 3 секунд, отправиться всем пользователям!')
        for i in text:
            try:
                bot.forward_message(i, message.chat.id, disable_notification=True, message_id=message.message_id)
            except:
                pass
                bot.send_message(message.chat.id, 'Все')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-04-24
@NHide

Something like this:

def all_id():
    conn = sqlite3.connect('base.db')
    cursor = conn.cursor()
    cursor.execute('SELECT id FROM users')
    words = cursor.fetchall()
    conn.commit()
    cursor.close()
    conn.close()
    return words

for x in all_id():
  print(x[0])

S
Sergey Gornostaev, 2020-04-24
@sergey-gornostaev

You return all_idonly one element from the function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question