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

Pyrogram raw函数channels.GetFullChannel调用失败问题排查

问题分析与解决

错误原因

你直接给functions.channels.GetFullChannel的channel参数传了整数类型的频道ID,但该参数要求传入Pyrogram Raw层的TL对象(具体为types.InputChannel),而非原始整数ID。报错AttributeError: 'int' object has no attribute 'write',本质是整数无法执行TL对象序列化所需的write()方法。

修正方案

需要用频道ID和对应的access_hash构造types.InputChannel对象,再传入GetFullChannel。具体步骤:

  1. 通过Pyrogram高层API获取频道的access_hash
  2. 用types.InputChannel封装频道ID与access_hash,作为参数传入

修正后的代码示例

from pyrogram import Client, filters, enums
from pyrogram.raw import functions, types

app = Client(username, api_id, api_hash)

@app.on_message(filters.text)
async def echo(client, message):
    if message.text == "test":
        # 获取频道的access_hash
        chat = await app.get_chat(-100********21)
        # 构造符合要求的InputChannel对象
        input_channel = types.InputChannel(
            channel_id=chat.id,
            access_hash=chat.access_hash
        )
        # 调用raw函数
        r = await app.invoke(functions.channels.GetFullChannel(channel=input_channel))
        print(r)

补充说明

  • Raw层函数的参数大多要求传入TL类型对象,而非直接传整数或字符串,这是Telegram底层API对身份标识序列化的要求
  • 针对不同场景,对应TL对象不同:用户用types.InputUser,普通聊天用types.InputPeerChat,需根据实际调用场景选择

内容的提问来源于stack exchange,提问作者user2956492

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 02:35:23