Friday, 27 August 2021

error_code":403,"description":"Forbidden: bot was blocked by the user. error handle in python

I have a problem using telebot API in python. If the user sends a message to the bot and waits for the response and at the same time he blocks the bot. I get this error and the bot will not respond for other users:

403,"description":"Forbidden: bot was blocked by the user

Try, catch block is not handling this error for me

any other idea to get rid of this situation? how to find out that the bot is blocked by the user and avoid replying to this message?

this is my code:

import telebot


@tb.message_handler(func=lambda m: True)
def echo_all(message):
    try:
           tb.reply_to(message, "response message") 
    except TelegramResponseException  as e:
            print(e) # do not handle error #403
    except Exception as e:
            print(e) # do not handle error #403
    except :
            print( "!!!!!!! user has been blocked !!!!!!!" ) # do not handle error #403
     


from error_code":403,"description":"Forbidden: bot was blocked by the user. error handle in python

No comments:

Post a Comment