diff --git a/telethon/client/auth.py b/telethon/client/auth.py index f310f5d3..94062d03 100644 --- a/telethon/client/auth.py +++ b/telethon/client/auth.py @@ -351,6 +351,7 @@ class AuthMethods(MessageParseMethods, UserMethods): Returns the input user parameter. """ + self._bot = bool(user.bot) self._self_input_peer = utils.get_input_peer(user, allow_self=False) self._authorized = True @@ -413,6 +414,7 @@ class AuthMethods(MessageParseMethods, UserMethods): except errors.RPCError: return False + self._bot = None self._self_input_peer = None self._authorized = False self._state = types.updates.State(0, 0, datetime.datetime.now(), 0, 0) diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index 0f111f9a..d048c492 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -289,6 +289,7 @@ class TelegramBaseClient(abc.ABC): # Sometimes we need to know who we are, cache the self peer self._self_input_peer = None + self._bot = None # endregion diff --git a/telethon/client/users.py b/telethon/client/users.py index 18c9c9d1..42581f98 100644 --- a/telethon/client/users.py +++ b/telethon/client/users.py @@ -110,6 +110,7 @@ class UserMethods(TelegramBaseClient): me = (await self( functions.users.GetUsersRequest([types.InputUserSelf()])))[0] + self._bot = me.bot if not self._self_input_peer: self._self_input_peer = utils.get_input_peer( me, allow_self=False @@ -119,6 +120,15 @@ class UserMethods(TelegramBaseClient): except errors.UnauthorizedError: return None + async def is_bot(self): + """ + Return ``True`` if the signed-in user is a bot, ``False`` otherwise. + """ + if self._bot is None: + self._bot = (await self.get_me()).bot + + return self._bot + async def is_user_authorized(self): """ Returns ``True`` if the user is authorized.