R
R
Revs12021-10-22 20:37:22
Python
Revs1, 2021-10-22 20:37:22

How to make a newsletter to Telegram users?

Hello.
I want to send a mailout to users of my bot by id through a txt file, but for some reason the id is not added to the txt file

Here is the code:

joinedFile = open("D:/бот/joined.txt",'r')
joinedUsers = set ()
for line in joinedFile:
  joinedUsers.add(line.strip())
joinedFile.close()	

@bot.message_handler(commands=['start'])
def startJoin(message):
  if not str(message.chat.id) in joinedUsers:
    joinedFile.open("D:/бот/joined.txt", 'a')
    joinedFile.write(str(message.chat.id) + "\n")
    joinedUsers.add(message.chat.id)

@bot.message_handler(commands=['special'])
def mess(message):
  for user in joinedUsers:
    bot.send_message(user,message.text[message.text.find(' '):])

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shurshur, 2021-10-22
@shurshur

Instead of:
joinedFile.open("D:/bot/joined.txt", 'a')
(which will still throw an error because the file object doesn't have an open method) do:
joinedFile = open("D:/bot/joined .txt", 'a')

A
Alan Gibizov, 2021-10-22
@phaggi

The correct mailing to telegram users is a special group "A group of people who want to receive mailings from my bot." Who subscribes to it - he will receive the newsletter in the form of a message in the group. Cheap, angry and direct.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question