Answer the question
In order to leave comments, you need to log in
How to make a newsletter for users in a telegram bot?
Well, for example, I write like this: /send Text. After that, a Text message is sent to all users.
Important: the command should be accessible only to the admin.
I have a database with the id of people who use the bot. (All/id.txt)
Using telebot
Answer the question
In order to leave comments, you need to log in
import telebot
API_TOKEN = ""
bot = telebot.TeleBot(API_TOKEN)
admins = [111, 222]
@bot.message_handler(commands=['send'])
def notify(message):
command_sender = message.from_user.id
if command_sender in admins:
with open(r'C:\id.txt') as ids:
for line in ids:
user_id = int(line.strip("\n"))
try:
bot.send_message(user_id, f'уведомление от {command_sender}')
except Exception as e:
bot.send_message(command_sender, f'ошибка отправки сообщения юзеру - {user_id}')
else:
bot.send_message(command_sender, f'у вас нет прав для запуска команды')
if __name__ == "__main__":
try:
bot.polling(none_stop=True)
except Exception as e:
pass
12345
777
34521
56213
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question