from telethon.sync import TelegramClient
from telethon import functions, types
def GetNum():
s_str = ""
number = '1838'
for i in range(7):
ch = chr(random.randrange(ord('0'), ord('9') + 1))
s_str += ch
return "{0}{1}".format(number, s_str)
def AddContact(m_contacts, client):
result = client(functions.contacts.ImportContactsRequest(
contacts=m_contacts
))
print(result.stringify())
i = 0
totel = 100
tel = 'XXXXXXXXX'
client = TelegramClient(tel, api_id, api_hash)
client.connect()
if not client.is_user_authorized():
client.send_code_request(tel)
me = client.sign_in(tel, input('Enter code: '))
if client.get_me("me") is not None:
contacts=[]
for n in range(100):
m_tel = GetNum()
i += 1
if i == 1:
print('Start to scan the number, the start number segment is: {}'.format(m_tel))
print("\r%d " % (totel-i), end='')
print("The number is: -{}".format(m_tel))
contact = types.InputPhoneContact(
client_id=random.randrange(-2**63, 2**63),
phone=m_tel,
first_name=m_tel,
last_name=' '
)
contacts.append(contact)
if n == totel:
print("A total of {1} numbers are added, and the final number is: {0}".format(m_tel, n))
AddContact(contacts, client)
client. disconnect()
如何在 telethon python 的联系人中保存号码?
授权和发送消息的过程是成功的,但是我找不到添加新用户到联系人列表的方法。
我在讨论中找到了解决方案,但没有用。执行代码后,联系人没有出现。在 api telegram python telethon 中添加新联系人 在 python 中添加与 telethon 的联系人
我尝试更改电话号码的格式并添加完全注册的用户 - 它没有帮助。
我在文档中也找不到合适的方法。
https://docs.telethon.dev/en/stable/modules/client.html#telethon.client.auth.AuthMethods.sign_up
提前谢谢你。