diff --git a/telethon/telegram_bare_client.py b/telethon/telegram_bare_client.py index 9d0c7bc5..0990fa27 100644 --- a/telethon/telegram_bare_client.py +++ b/telethon/telegram_bare_client.py @@ -103,15 +103,8 @@ class TelegramBareClient: If 'exported_auth' is not None, it will be used instead to determine the authorization key for the current session. """ - if self._sender and self._sender.is_connected(): - # Try sending a ping to make sure we're connected already - # TODO Maybe there's a better way to check this - try: - self(PingRequest(utils.generate_random_long())) - return True - except: - # If ping failed, ensure we're disconnected first - self.disconnect() + if self.is_connected(): + return True connection = Connection( self.session.server_address, self.session.port, @@ -168,6 +161,9 @@ class TelegramBareClient: ) return False + def is_connected(self): + return self._sender is not None and self._sender.is_connected() + def _init_connection(self, query=None): result = self(InvokeWithLayerRequest(LAYER, InitConnectionRequest( api_id=self.api_id,