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) phone = utils.parse_phone(string)
if phone: if phone:
for user in (await self( try:
functions.contacts.GetContactsRequest(0))).users: for user in (await self(
if user.phone == phone: functions.contacts.GetContactsRequest(0))).users:
return user 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: else:
username, is_join_chat = utils.parse_username(string) username, is_join_chat = utils.parse_username(string)
if is_join_chat: if is_join_chat: