T
T
TeleBot20202020-01-14 23:41:13
Python
TeleBot2020, 2020-01-14 23:41:13

How to create a competent telegram bot mailing list?

I made a mailing list in a cycle, it takes the chatid from the txt file, but as soon as it comes across the id of the person who stopped and banned the bot, the mailing stops, an error 403 falls out. How to write a mailing list correctly? Thanks in advance!

elif message.text == "send":
    
        request = 0
        handle = open("bot_usr.txt", "r")
        for line in handle:
            bot.send_message(line,"текст рассылки",parse_mode='markdown')
            request = request + 1
            time.sleep(0.5)
            if request % 30 == 0:
                time.sleep(1.5)
                request = 0
        handle.close()

Mistake:
ERROR - TeleBot: "ApiException occurred, args=('A request to the Telegram API was unsuccessful. The server returned HTTP 403 Forbidden. Response body:\n[b\'{"ok":false,"error_code":403,"description":"Forbidden: bot was blocked by the user"}\']',)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2020-01-15
@TeleBot2020

Use sqlite3 or another database for convenience and use try:, except: to catch this error and then delete the id from the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question