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

Telethon JoinChatlistInviteRequest报错:include_peers向量为空问题排查

问题解决:Telethon调用JoinChatlistInviteRequest提示include_peers为空

错误原因

你混淆了JoinChatlistInviteRequest的参数逻辑:错误地将需要放入filter的会话列表传给了peers参数,而该请求要求必须提供包含非空include_peers的ChatlistFilter。你的代码未设置filter参数,导致默认的filter中include_peers为空,触发了API报错。

修正后的代码

from telethon.sync import TelegramClient
from telethon import functions, types

api_id = '****'
api_hash = '****'

phone_number = '+****'

with TelegramClient(phone_number, api_id, api_hash) as client:
    try:
        # 注意:如果要加入的是频道/群组,需改用对应的get_entity和InputPeer类型
        target_peer = client.get_entity('@****')
        input_peer = types.InputPeerUser(user_id=target_peer.id, access_hash=target_peer.access_hash)
        
        # 构造ChatlistFilter并传入include_peers
        chat_filter = types.ChatlistFilter(include_peers=[input_peer])
        
        result = client(functions.chatlists.JoinChatlistInviteRequest(
            slug='https://t.me/addlist/****',
            filter=chat_filter
        ))
        print(result.stringify())
    except Exception as e:
        print(f"Error: {e}")

关键说明

  1. 参数区分:JoinChatlistInviteRequest的peers参数(若存在)用于指定需要更新的会话,而非筛选要加入的会话;真正控制加入范围的是filter参数内的include_peers列表。
  2. Peer类型匹配:如果你的目标是加入频道或群组,需将InputPeerUser替换为InputPeerChannel或InputPeerChat,同时确保get_entity获取的是对应类型的实体。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 04:01:02