Skip to content

[QUESTION] How to check if a user block and stop bot #2485

Answered by Bibo-Joshi
bsimjoo asked this question in Q&A
Discussion options

You must be logged in to vote

As of API 5.1 you will get an update with update.my_chat_member, where update.my_chat_member.new_chat_member.status can be used to check if the bot has been blocked. In PTB v13.4+ you can use ChatMemberHandler to catch those updates.
Nevertherless, handling exceptions is a very sane & advisable thing to do. IIRC Unauthorized is raised when the user has blocked the bot, but you can also check the exception message (str(e)) to see that.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by bsimjoo
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2484 on April 24, 2021 06:48.