【问题标题】:List of kicked/banned users in a Telegram group/channel using telethon使用 Telethon 的 Telegram 组/频道中被踢/禁止的用户列表
【发布时间】:2021-07-23 08:06:32
【问题描述】:

使用telethon,您几乎可以在 Telegram 周围做任何您想做的事情。但是,我找不到获取组/频道中已删除(禁止)用户列表的方法。有什么想法吗?

作为记录,您可以通过 Telegram 的 GUI 访问 Edit > Permissions > Removed Users

【问题讨论】:

    标签: telegram telethon


    【解决方案1】:

    要使用 Telethon 获取 Telegram 组/频道中所有已删除用户的列表,您需要使用 get_participants() 并将 filter 参数设置为 ChannelParticipantsKicked

    from telethon.tl.types import ChannelParticipantsKicked # import type to use as filter
    kicked_members = await client.get_participants(chat, filter=ChannelParticipantsKicked)
    

    如果您希望循环遍历结果而不将其分配给变量,您可以改用iter_participants()

    from telethon.tl.types import ChannelParticipantsKicked 
    async for user in client.iter_participants(chat, filter=ChannelParticipantsKicked):
        print(user.first_name)
    

    NR:这里列出了所有可用的 filtersget/iter_participants() 一起使用。

    【讨论】:

    • 嗯,没错,Telegram 有这种“禁止”人的特殊方式,实际上将他们保留在频道/组中,但删除了他们查看内容的权限。
    【解决方案2】:

    @client.on(events.NewMessage(pattern="/[Bb]anlist",from_users=admin)) async def banlist(事件): text = (event.raw_text).split(" ") 尝试: 禁令 = 等待 client.get_participants(text[1] , filter=ChannelParticipantsKicked) 禁止列表 = "" 对于我在禁令中: if (i.username != None): ban_list += "@" + i.username +'\n' await event.reply("BAN LSIT: {}".format(ban_list)) 除了: await event.reply("ERROR!")

    【讨论】:

    • 建议:添加代码围栏和语言标识符以突出显示代码并使其更具可读性。
    猜你喜欢
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    • 2017-02-10
    • 2020-07-01
    相关资源
    最近更新 更多