【问题标题】:What should I do if I want tag all members of a group in telegram python bot?如果我想在电报 python bot 中标记一个组的所有成员,我该怎么办?
【发布时间】:2020-12-26 02:42:07
【问题描述】:

我有一个在 python 上运行并基于 Telethon 库的电报机器人。我想标记一个组中的所有成员,但我的代码源有 100 个用户标记限制,当我想将其数量增加到 500 个用户甚至更多时,它不会标记整个用户,只是给我他们的名字,只是标记前 100 个用户。请帮助我如何在不给用户计数的情况下标记组中的所有成员。代码如下:

import asyncio
from telethon import events
from telethon.tl.types import ChannelParticipantsAdmins

async def _(event):
    if event.fwd_from:
        return
    mentions = "All members tagged successfully!"
    chat = await event.get_input_chat()
    async for x in borg.iter_participants(chat, 100):
        mentions += f" \n [{x.first_name}](tg://user?id={x.id})"
    await event.reply(mentions)
    await event.delete()

我可以通过这些代码在组中标记管理员:

async def _(event):
    if event.fwd_from:
        return
    mentions = "Administrators in the chat : "
    chat = await event.get_input_chat()
    async for x in borg.iter_participants(chat, filter=ChannelParticipantsAdmins):
        mentions += f" \n [{x.first_name}](tg://user?id={x.id})"
    reply_message = None
    if event.reply_to_msg_id:
        reply_message = await event.get_reply_message()
        await reply_message.reply(mentions)
    else:
        await event.reply(mentions)
    await event.delete()

我可以在上面的代码中添加像 ChannelParticipantsAdmins 这样的过滤器,而不是在之前的代码中添加 100 个用户数吗?如果是,过滤器部分应该是什么。

感谢您的帮助。

【问题讨论】:

  • 使用 pin 消息。
  • Telegram 限制了您可以在一条消息中标记的人数。上次我听说限制是 50。就像@itsapk 所说,最好只是固定并通知消息。

标签: python tags telegram telegram-bot telethon


【解决方案1】:

https://github.com/micodev/botShell/blob/master/plugins/tagAll.py 访问上面的链接,它向您展示了一种实现您想法的方法,您可以在一条消息中发送 8 个用户名,以使其适用于所有成员或使用 pin 消息。

【讨论】:

    猜你喜欢
    • 2020-03-26
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-25
    • 1970-01-01
    • 2021-10-16
    相关资源
    最近更新 更多