Telethon:如何上传频道/聊天徽标?

时间:2018-09-12 08:36:45

标签: python telegram telethon

如何上传频道/聊天徽标?我在官方文档中找不到此信息。

1 个答案:

答案 0 :(得分:0)

您可以使用此代码更改频道的头像:

i使用EditPhotoRequestInputChatUploadedPhoto更改频道的头像( test_ali3 )。

from telethon import TelegramClient, events, sync
from telethon.tl.functions.channels import EditPhotoRequest
from telethon.tl.types import InputChatUploadedPhoto

api_id = XXXXXX
api_hash = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
phone_number = '+989XXXXXXXXX'
################################################
channel_username = "test_ali3"
################################################

client = TelegramClient('session_name',
                    api_id,
                    api_hash,
                    )
client.start()

channel_entity = client.get_entity(channel_username)
upload_file_result = client.upload_file(file='images/amnesic98.jpg')
input_chat_uploaded_photo = InputChatUploadedPhoto(upload_file_result)
try:
   result = client(EditPhotoRequest(channel=channel_entity, 
photo=input_chat_uploaded_photo))
except BaseException as e:
    print(e)

print('finish')
相关问题