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

如何获取Telegram群组200名以上成员?及现有方案问题咨询

Telegram群组成员获取限制问题

我搞不懂为什么没法获取Telegram群组里200名以上的成员。目前只能通过迭代过滤器的方式拿到部分成员,但这种方法拿不到群组里的已注销账号(只有用户ID、没有其他数据的账号)。

我找到的所有解决方案要么过时没用,要么根本跑不起来。

require('dotenv').config();
const { TelegramClient, Api } = require("telegram");
const { StringSession } = require("telegram/sessions");
const input = require("input");

if (!process.env.API_ID || !process.env.API_HASH) {
  console.error("API_ID и API_HASH в .env файле.");
  process.exit(1);
}

const apiId = parseInt(process.env.API_ID);
const apiHash = process.env.API_HASH;

const stringSession = new StringSession("");
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

const generateHash = (ids) => {
  let hash = 0;
  for (const id of ids) {
    hash = hash ^ (hash >> 21);
    hash = hash ^ (hash << 35);
    hash = hash ^ (hash >> 4);
    hash = hash + id;
  }
  return hash;
};

(async () => {
  const client = new TelegramClient(stringSession, apiId, apiHash, {
    connectionRetries: 5,
  });

  await client.start({
    phoneNumber: async () => await input.text("Номер ?"),
    password: async () => await input.text("Пароль ?"),
    phoneCode: async () => await input.text("Код ?"),
    onError: (err) => console.log(err),
  });

  const groupId = await input.text("ID группы: ");
  const allParticipants = [];
  const uniqueParticipants = new Set();

  try {
    let offset = 0;
    const limit = 200;
    let hash = 200;
    let nextBatch = true;

    while (nextBatch) {
      try {
        const participants = await client.invoke(
          new Api.channels.GetParticipants({
            channel: groupId,
            filter: new Api.ChannelParticipantsSearch({ q: "" }), 
            offset: offset,
            limit: limit,
            hash: hash,
          })
        );

        if (participants.participants.length > 0) {
          const ids = [];
          participants.participants.forEach((user) => {
            const userId = user.userId.valueOf();
            if (!uniqueParticipants.has(userId)) {
              uniqueParticipants.add(userId);
              const telegramUser = participants.users.find((u) => u.id.valueOf() === userId);
              const firstName = telegramUser?.firstName || "Не указано";
              const lastName = telegramUser?.lastName || "Не указано";
              const username = telegramUser?.username || "Не указано";

              allParticipants.push({
                group_id: groupId,
                id: telegramUser.id.valueOf(),
                username: username,
                first_name: firstName,
                last_name: lastName,
                phone: telegramUser.phone || "",
                is_premium: telegramUser.premium ? "Yes" : "No",
              });
              ids.push(userId);
            }
          });

          offset += participants.participants.length;
          hash = generateHash(ids);
          nextBatch = participants.participants.length === limit; 
        } else {
          nextBatch = false;  
        }

      } catch (error) {
        console.error("Ошибка при извлечении участников:", error);
        nextBatch = false; 
      }

      await delay(2000); 
    }

    console.log("Извлечённые участники:", allParticipants);
  } catch (error) {
    console.error("Ошибка при загрузке участников:", error);
  } finally {
    await client.disconnect();
    process.exit(0);
  }
})();

是不是Telegram官方已经封禁了这种获取成员列表的方法?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 06:23:24