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

无需使用机器人,如何获取Telegram群组中多个投票的投票者名单?

解决方案

可以用支持Telegram MTProto协议的第三方库,比如Pyrogram或Telethon,这类库允许你使用个人账号(而非机器人账号)登录Telegram,直接获取群组里的投票数据,不需要额外添加机器人到群组。

具体步骤(以Telethon为例):

  1. 安装Telethon库:
pip install telethon
  1. 获取Telegram API凭证:
    • 前往Telegram开发者平台,用个人账号登录后创建应用,获取api_id和api_hash。
  2. 编写脚本获取投票者名单:
from telethon import TelegramClient
from telethon.tl.types import MessageMediaPoll

# 替换为你的api_id、api_hash和会话名称
api_id = 123456
api_hash = 'your_api_hash_here'
client = TelegramClient('my_session', api_id, api_hash)

async def get_voters():
    # 替换为目标群组的ID或用户名
    chat = 'your_group_username_or_id'
    async for message in client.iter_messages(chat):
        if message.media and isinstance(message.media, MessageMediaPoll):
            poll = message.media.poll
            # 获取投票结果(包含投票者信息,需群组权限允许查看)
            results = await client.get_poll_results(message)
            for idx, option in enumerate(results.results):
                print(f"选项: {poll.answers[idx].text}")
                print(f"投票者数量: {option.voters}")
                # 如果有权限,可获取具体投票者列表
                if option.voters > 0:
                    voters = await client.get_poll_voters(message, idx)
                    for voter in voters:
                        print(f"- {voter.first_name} (@{voter.username})")

with client:
    client.loop.run_until_complete(get_voters())

注意事项:

  • 确保你的个人账号在目标群组中有足够权限(比如能查看投票详情的权限,部分群组可能限制普通成员查看投票者)。
  • 使用个人账号登录时,首次需要验证手机号(会发送验证码)。
  • Pyrogram的实现逻辑类似,核心都是通过个人账号的会话直接访问群组数据,无需机器人加入。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 22:50:37