From ca2c8687c8d0a96d4b572332f08849f4bc0852bb Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 8 Jan 2019 10:58:58 +0100 Subject: [PATCH] Expect UserEmpty on get_input_entity --- telethon/client/users.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/telethon/client/users.py b/telethon/client/users.py index 42581f98..16af8b4d 100644 --- a/telethon/client/users.py +++ b/telethon/client/users.py @@ -322,7 +322,14 @@ class UserMethods(TelegramBaseClient): if isinstance(peer, types.PeerUser): users = await self(functions.users.GetUsersRequest([ types.InputUser(peer.user_id, access_hash=0)])) - if users: + if users and not isinstance(users[0], types.UserEmpty): + # If the user passed a valid ID they expect to work for + # channels but would be valid for users, we get UserEmpty. + # Avoid returning the invalid empty input peer for that. + # + # We *could* try to guess if it's a channel first, and if + # it's not, work as a chat and try to validate it through + # another request, but that becomes too much work. return utils.get_input_peer(users[0]) elif isinstance(peer, types.PeerChat): return types.InputPeerChat(peer.chat_id)