Слишком много ошибок RuntimeWarning - PullRequest
0 голосов
/ 20 января 2020

Я пишу код, который должен добавить пользователя в контакты по номеру телефона и добавить его в канал телеграммы: из telethon импортировать TelegramClient из telethon.tl.functions.messages import AddChatUserRequest из telethon.tl.types import InputPhoneContact from telethon .tl.functions.contacts import ImportContactsRequest

api_id = XXXXXXX
api_hash = 'XXXXXXXXXXXXX'
phone_number = "XXXXXXXXXXX" 
group_id = XXXXXXXXXXX
guest_phone_number="XXXXXXXXXXX"
client = TelegramClient('session_name', api_id, api_hash) 
client.start()

assert client.connect() 
if not client.is_user_authorized(): 
    client.send_code_request(phone_number ) 
    me = client.sign_in(phone_number, input('Enter code: ')) 
# add user to contact 
contact = InputPhoneContact(client_id=0, phone=guest_phone_number, first_name="custom_first_name", last_name="custom_last_name") 
result = client(ImportContactsRequest([contact]))
# add contact to the group 
client(AddChatUserRequest(user_id=result.users[0], fwd_limit=0, chat_id=group_id)) 

И это дает мне следующее:

/storage/sdcard0/telegram2.py:19: RuntimeWarning: coroutine 'TelegramBaseClient.connect' was never awaited
assert client.connect()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
/storage/sdcard0/telegram2.py:20: RuntimeWarning: coroutine 'UserMethods.is_user_authorized' was never awaited
if not client.is_user_authorized():
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
File "/data/data/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
File "/data/data/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
File "<string>", line 30, in <module>
TypeError: __init__() got multiple values for argument 'chat_id'
sys:1: RuntimeWarning: coroutine 'UserMethods.__call__' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

[Program finished]

Помогите пожалуйста (

...