S
S
StenMarsh13372020-10-20 11:39:21
Python
StenMarsh1337, 2020-10-20 11:39:21

How to find out which user blocked the bot?

There is a script for sending letters, I can prodynamize the user who blocked the bot, but how to find out which user with the user_id from the file blocked it?

try:
            text = message.text
            handle = open("Users/chatid_list.txt", "r")
            for line in handle:
                bot.send_message(line, text)
            handle.close()
        except:
            bot.send_message(message.chat.id, 'Заблокировали бота - ')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2020-10-20
@StenMarsh1337

Well, an exception happens when sending a specific id - so display this id.
By the way, in except it is better to specify a specific type of exception. Because a ConnectionError may happen due to a downed network or a Telegram failure - and the bot will decide that everyone has blocked it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question