From 34cefed9ff51e7444b011f1804891a6cfd3b76ea Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 15 Oct 2018 18:42:35 +0200 Subject: [PATCH] Except BotMethodInvalidError on getContacts --- telethon/client/users.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/telethon/client/users.py b/telethon/client/users.py index ccbdc5e7..56cc39ca 100644 --- a/telethon/client/users.py +++ b/telethon/client/users.py @@ -354,10 +354,14 @@ class UserMethods(TelegramBaseClient): """ phone = utils.parse_phone(string) if phone: - for user in (await self( - functions.contacts.GetContactsRequest(0))).users: - if user.phone == phone: - return user + try: + for user in (await self( + functions.contacts.GetContactsRequest(0))).users: + if user.phone == phone: + return user + except errors.BotMethodInvalidError: + raise ValueError('Cannot get entity by phone number as a ' + 'bot (try using integer IDs, not strings)') else: username, is_join_chat = utils.parse_username(string) if is_join_chat: