在python中添加与telethon的联系 [英] add contact with telethon in python

查看:63
本文介绍了在python中添加与telethon的联系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据本教程,最近我尝试使用 Telethon 在电报中添加联系人:1) 在api电报python Telethon中添加新联系人,我用了这个代码:

Recently I tried to add contact in telegram with telethon, according to this tutorial: 1) Add new contact in api telegram python telethon ,I used this codes:

contact = InputPhoneContact(client_id=0, phone='+989122725691', first_name="user",
                        last_name="test")
result = ImportContactsRequest(contacts=[contact])
print(result)

但我在我的输出中得到了这个:

But I in my output I get this :

ImportContactsRequest(contacts=[InputPhoneContact(client_id=0, phone='+989122725691', first_name='user', last_name='test')])

我不知道我的问题是什么,但是当我转到我的电报应用程序时,没有添加此联系人.

I can'd find out what is my problem, but when I go to my telegram app, this contact isn't add.

推荐答案

您应该使用您的客户端实例调用 ImportContactsRequest.例如

you should call ImportContactsRequest with your client Instance. e.g.

import random
contact = InputPhoneContact(client_id=random.randint(0,9999), phone='+98912******', 
    first_name="user",
    last_name="test")
result = client(ImportContactsRequest(contacts=[contact]))
print(result.__dict__)

作者注

我们过去曾遇到过问题.

这篇关于在python中添加与telethon的联系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆