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

使用WTelegramClient获取Telegram频道成员仅返回200条问题求助

问题解决思路与方案

Telegram 官方对 channels.getParticipants 接口原生限制了 offset 偏移量超过 200 后不再返回更多数据,并非代码逻辑错误或 WTelegramClient 库的问题。

  • 改用 offset_date 分页逻辑绕开 200 条限制
    放弃原有仅依赖 offset 递增的分页逻辑,每次拉取成员时记录当前返回列表最后一个成员的 participant.date 值,下一次调用 Channels_GetParticipants 时,将 offset 重置为 0,同时将记录的最后日期传入 offset_date 参数,即可继续拉取更早加入的成员,直到返回的参与者列表为空即可终止循环。
  • 修复封禁权限配置错误
    你当前代码中 bannedRights.flags 设为 0,没有配置任何封禁权限,调用封禁接口不会生效。要实现移除用户的效果,需配置封禁查看消息权限,设置永久生效即可将用户踢出频道。
  • 增加接口调用速率控制
    Telegram 对高频接口调用有严格的风控规则,拉取成员时建议每两次 Channels_GetParticipants 请求间隔 1 秒,每执行 10 次 Channels_EditBanned 操作后暂停 3-5 秒,避免触发临时限流甚至账号封禁。
  • 可选优化:定向捞取目标日期用户
    如果你仅需要处理指定日期加入的用户,不需要全量拉取所有成员,可以在调用 Channels_GetParticipants 时传入对应日期作为 offset_date 起始值,直接拉取目标日期范围内的成员,减少不必要的接口调用。

修改后的参考代码如下:

var deleted = new List<User>();
var bannedRights = new ChatBannedRights
{
    view_messages = true,
    until_date = 0 // 0代表永久封禁,用户被踢出后无法重新加入频道
};

DateTime? lastParticipantDate = null;
while (true)
{
    // 第一次调用offset_date传null,后续传上一次最后一个成员的加入日期,offset固定为0
    var participants = await client.Channels_GetParticipants(channel, null, 0, 100, accessHash, lastParticipantDate);
    
    if (participants.participants.Length == 0) break;
    
    foreach (var participant in participants.participants.OfType<ChannelParticipant>())
    {
        var member = (User)participants.users[participant.user_id];
        if (participant.date.Date == _joinedOn.Date)
        {
            Console.WriteLine($"Removing user '{member.username}' as joined on {_joinedOn:yyyy-MM-dd}...");
            await client.Channels_EditBanned(channel, member, bannedRights);
            deleted.Add(member);
            // 每处理10个用户暂停3秒,可根据实际情况调整
            if (deleted.Count % 10 == 0) await Task.Delay(3000);
        }
        // 更新最后一个成员的日期,用于下一页拉取
        lastParticipantDate = participant.date;
    }
    // 每次拉取后暂停1秒,避免限流
    await Task.Delay(1000);
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.23 20:24:04