Except BotMethodInvalidError on getContacts

This commit is contained in:
Lonami Exo 2018-10-15 18:42:35 +02:00
parent 99129daeee
commit 34cefed9ff

View File

@ -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: