You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 00:22:02