Answer the question
In order to leave comments, you need to log in
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
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')
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 questionAsk a Question
731 491 924 answers to any question