Answer the question
In order to leave comments, you need to log in
How to fix error in streams (telethon library or pytelegrambotapi)?
In a bot running on the pytelegrambotapi library, I try to find an id using the telethon library (by adding it to contacts). When I call, in a separate telethon file, then everything works. When I try to call a method from a script with the telethon library in the pytelegrambotapi bot through a button and a class, an error occurs, can it be fixed?
class GetIdbyPhone():
@staticmethod
def getIdUserByPhone(phone):
client = TelegramClient(username, api_id, api_hash)
result = client(functions.contacts.ImportContactsRequest(
contacts=[types.InputPhoneContact(
client_id=0,
phone=phone,
first_name='Alex',
last_name=""
)]
))
for i in result.users:
data = str(i.id)
return data
@classmethod
def tryThread(cls, phone):
loop.create_task(cls.getIdUserByPhone(phone))
loop.run_until_complete()
Answer the question
In order to leave comments, you need to log in
from asyncio import set_event_loop, new_event_loop
set_event_loop(new_event_loop())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question