Answer the question
In order to leave comments, you need to log in
Newsletter on telebot?
Hello. There is a database where the id of users who used the bot
is stored, the file name is user.db
The table is called login_id and the id is stored in id
Tell me how you can make a newsletter?
@bot.message_handler(commands=['start'])
def start(message):
bot.send_message(message.chat.id, 'Пᴘивᴇт, мᴇня зᴀвʏт \n Я являюсь твоим помоωником в иrᴘᴇ с чᴇм тᴇҕᴇ помочь ? ', reply_markup=markup)
bot.send_photo(message.chat.id, get("https://i.imgur.com/qyn4g24.jpg").content)
#data base
connect = sqlite3.connect('users.db')
cursor = connect.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS login_id(
id INTEGER
)""")
connect.commit()
#повтор ид
people_id = message.chat.id
cursor.execute(f"SELECT id FROM login_id WHERE id = {people_id}")
data = cursor.fetchone()
if data is None :
user_id = [message.chat.id]
cursor.execute("INSERT INTO login_id VALUES(?);", user_id)
connect.commit()
else:
bot.send_message(message.chat.id, 'С возврашением')
Answer the question
In order to leave comments, you need to log in
Telegram does not have a function to send a message to all users at once. Therefore, it is necessary to store the user_id of all users. If this is already there, then implement the simplest distribution mechanism via sendMessage (according to the official Telegram documentation )
def rassilka(message):
cursor.execute('SELECT id FROM login_id')
result = cursor.fetchall()
msg = '[Тут рассылаемое сообщение]'
for x in result:
bot.send_message(x[YOU_BD_NUMBER], str(msg))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question