Telethon: How to check if user is banned?

Created on 28 Apr 2018  路  4Comments  路  Source: LonamiWebs/Telethon

Hello. This library is awesome! I use Telethon 0.18.3 and Python 3.6.

I read exceptions in rpc_error_list, and I figured out that there are UserBlockedError, UserIsBlockedError, PhoneNumberBannedError etc. Can I catch one of these (f. e. PhoneNumberBannedError when I try to send_code_request or UserBlockedError when I try sign_in) to determine that user is banned by Telegram? I didn't find enough info about it in docs :(

P. S. Sorry for my English

Most helpful comment

@kaxap as a side note, errors are re-exported on telethon.errors, so telethon.errors.PhoneNumberBannedError is perfectly valid too. Thanks for helping out nevertheless.

All 4 comments

Just catch the telethon.errors.rpc_error_list.PhoneNumberBannedError exception during client.send_code_request()

    this_client = TelegramClient(phone_number, api_id, api_hash)
    this_client.connect() 
    if not this_client.is_user_authorized():
        try:
            this_client.send_code_request(phone_number)
        except telethon.errors.rpc_error_list.PhoneNumberBannedError:
            print("Phone number is banned.")
            this_client.disconnect()

Ok, thank you! But why there is no PhoneNumberBannedError in https://core.telegram.org/method/auth.sendCode Possible errors?

I just realized that official docs are outdated, so I found more info here https://lonamiwebs.github.io/Telethon/methods

Thank you!

@kaxap as a side note, errors are re-exported on telethon.errors, so telethon.errors.PhoneNumberBannedError is perfectly valid too. Thanks for helping out nevertheless.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adv-zl picture adv-zl  路  3Comments

saharokk picture saharokk  路  3Comments

iranpak picture iranpak  路  3Comments

justxor picture justxor  路  4Comments

ksanderer picture ksanderer  路  3Comments