Skip to content

Telethon fails to detect invalidated bot token or deleted/banned bot session after initial authorization #4681

@viraj-bookanna

Description

@viraj-bookanna

Code that causes the issue

After starting a bot with a valid token, Telethon correctly connects and authorizes.

However, if the bot token is later:
Revoked (via BotFather),
The bot is deleted,
Or banned by Telegram,

Lines of code:

was_once_logged_in = self._authorized is True or not self._message_box.is_empty()

if was_once_logged_in:

if was_once_logged_in:

Expected behavior

If the bot gets unauthorized after original auth, (was_once_logged_in). It should disconnect

Actual behavior

It just prints in the log (Cannot get difference since the account is not logged in .....) and still keep the connection

Traceback

xxxx-xx-xx xx:xx:xx,xxx- telethon.client.updates - INFO - Cannot get difference since the account is not logged in: SessionRevokedError

Telethon version

1.40.0

Python version

3.11.13

Operating system (including distribution name and version)

Windows 11, Ubuntu 22.04

Other details

No response

Checklist

  • The error is in the library's code, and not in my own.
  • I have searched for this issue before posting it and there isn't an open duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions