diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index 46b88887..0db78847 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -79,9 +79,6 @@ class TelegramClient: self.sender = None self.phone_code_hashes = {} - # We need to be signed in before we can listen for updates - self.signed_in = False - # endregion # region Connecting @@ -121,8 +118,6 @@ class TelegramClient: # although many other options are available! self.dc_options = result.dc_options - # We're signed in if we're authorized - self.signed_in = self.is_user_authorized() return True except RPCError as error: print('Could not stabilise initial connection: {}'.format(error)) @@ -241,9 +236,6 @@ class TelegramClient: self.session.user = result.user self.session.save() - # Now that we're authorized, set the signed_in flag - # to True so update handlers can be added - self.signed_in = True return True def sign_up(self, phone_number, code, first_name, last_name=''): @@ -728,9 +720,9 @@ class TelegramClient: def add_update_handler(self, handler): """Adds an update handler (a function which takes a TLObject, an update, as its parameter) and listens for updates""" - if not self.signed_in: - raise ValueError( - "You cannot add update handlers until you've signed in.") + if not self.sender: + raise RuntimeError( + "You should connect at least once to add update handlers.") self.sender.add_update_handler(handler)