如何用Pyrogram/Telegram API创建群组话题并上传文件?
使用Pyrogram向群组话题上传文件及创建话题的方法
向指定话题上传内容
Pyrogram的send_video方法支持通过message_thread_id参数指定论坛话题ID,直接在现有代码中添加该参数即可:
with Client('my_account', api_id, api_hash) as client: client.send_video( chat_id=username, video=video_path, thumb=thumbnail_path, duration=int(duration), supports_streaming=True, message_thread_id=你的话题ID # 填入目标话题的整数ID )
话题ID为整数类型,可通过群组话题链接或客户端内的话题详情获取对应值。
创建新的群组话题
使用Pyrogram的create_forum_topic方法可直接创建新话题,方法返回的对象中包含该话题的ID,可直接用于后续内容发布:
with Client('my_account', api_id, api_hash) as client: # 创建新话题 new_topic = client.create_forum_topic( chat_id=username, title="自定义话题标题" # 替换为你需要的话题名称 ) # 向新创建的话题上传视频 client.send_video( chat_id=username, video=video_path, thumb=thumbnail_path, duration=int(duration), supports_streaming=True, message_thread_id=new_topic.message_thread_id )
内容的提问来源于stack exchange,提问作者Jamie Karvan
相关产品推荐
相关产品推荐

