如何在 Telegram 中显示频道 ID。
for mes in msgs:
with TelegramClient(Phone, api_id, api_hash) as client:
result = client(functions.messages.GetAllChatsRequest(
except_ids=[42]
))
print(result.stringify('id'))
был такой еще вариант
print(result.stringify(['channel', 'id']))
#my_file = open('test.txt', 'a')
#my_file.write(result.stringify()+'\n')
#print("TEST")
time.sleep(6)
它只是显示有关频道的所有信息。
错误
print(result.stringify('id')) TypeError: stringify() 接受 1 个位置参数,但给出了 2 个
Channel(
id=1499501182,
title='Тут было название канала',
photo=ChatPhoto(
photo_small=FileLocationToBeDeprecated(
volume_id=200006400504,
local_id=390002
),
photo_big=FileLocationToBeDeprecated(
volume_id=200006400504,
local_id=390004
),
dc_id=2
),
date=datetime.datetime(2020, 7, 14, 11, 15, 37, tzinfo=datetime.timezone.utc),
version=0,
creator=False,
left=False,
broadcast=True,
verified=False,
megagroup=False,
restricted=False,
signatures=False,
min=False,
scam=False,
has_link=False,
has_geo=False,
slowmode_enabled=False,
access_hash=6797022806759780742,
username='Тут было название канала',
restriction_reason=[
],
admin_rights=None,
banned_rights=None,
default_banned_rights=None,
participants_count=None
),
试试看
result.to_dict()['chats'][0]['id']
您可以简单地将答案转换为字典并通过键访问其元素