简体   繁体   English

Telethon Bot - 如何检查用户是否通过用户 ID 订阅了我的频道

[英]Telethon Bot - how to check if a user is subscribed to my channel by user's id

Via my telegram bot I have to check if the user who texting the bot is in my telegram channel or not, I tried:通过我的电报机器人,我必须检查发短信给机器人的用户是否在我的电报频道中,我试过:

        user_id = event.message.peer_id.user_id #user's id
        async for i in bot.iter_participants(mychannelID, filter=ChannelParticipantsRecent):
            if user_id != i.id:
                status = False
            else:
                status = True
                break

it worked only on my localhost, but on my Linux server it results an error:它只在我的本地主机上工作,但在我的 Linux 服务器上它会导致错误:

Traceback (most recent call last):
  File "/home/runner/ConcernedHonoredVolume-rcmov/venv/lib/python3.8/site-packages/telethon/client/updates.py", line 467, in _dispatch_update
    await callback(event)
  File "main.py", line 226, in enter
    async for i in bot.iter_participants(MAIN_CHANNEL_ID, filter=ChannelParticipantsRecent):
  File "/home/runner/ConcernedHonoredVolume-rcmov/venv/lib/python3.8/site-packages/telethon/requestiter.py", line 58, in __anext__
    if await self._init(**self.kwargs):
  File "/home/runner/ConcernedHonoredVolume-rcmov/venv/lib/python3.8/site-packages/telethon/client/chats.py", line 111, in _init
    entity = await self.client.get_input_entity(entity)
  File "/home/runner/ConcernedHonoredVolume-rcmov/venv/lib/python3.8/site-packages/telethon/client/users.py", line 466, in get_input_entity
    raise ValueError(
ValueError: Could not find the input entity for PeerUser(user_id=******8242) (PeerUser). Please read https://docs.telethon.dev/en/latest/concepts/entities.html to find out more details.

I have already read entities.html as mentioned, but nothing is working.如前所述,我已经阅读了entities.html ,但没有任何效果。

Also I tried:我也试过:

        result = await bot(functions.channels.GetParticipantsRequest(
            channel='username',
            filter=types.ChannelParticipantsRecent(),
            offset=42,
            limit=20,
            hash=0
        ))
        if user_id not in result:
            ...

but I keep getting TypeError: argument of type 'ChannelParticipants' is not iterable但我不断收到TypeError: argument of type 'ChannelParticipants' is not iterable

It turns out that I had to re-add my bot to the channel, because the bot lost access hash to the channel when I moved it to another device, since access hash is stored in the .session file and lost after the transfer.事实证明,我不得不将我的机器人重新添加到频道,因为当我将机器人移动到另一台设备时,机器人失去了对频道的访问权限 hash,因为访问权限 hash 存储在.session文件中,并在传输后丢失。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查用户是否订阅了特定的 Telegram 频道(Python / PyTelegramBotApi)? - How to check if a user is subscribed to a specific Telegram channel (Python / PyTelegramBotApi)? 如何使用 Telethon 获取转发消息的频道/聊天/用户名? - How to get channel/chat/user name of forwarded message using Telethon? 我如何使用用户 ID 将其与条件匹配,以便当用户向频道发送消息时,机器人可以为用户执行特定任务 - how do i use user's ID for matching it with a condition so that when the user sends message to channel, the bot can do specific tasks for the user 如何让我的机器人从用户运行命令的位置获取通道 ID? (不和谐.py) - How do I make my bot get the channel Id from where the user ran the command from? (Discord.py) 如何检查在我的机器人上使用命令的人的用户 ID - How can I check the user ID of someone who uses a command with my bot 如何检查机器人用户是特定聊天或电报频道的成员? python电报机器人 - how to check bot-user is member of specific chat or telegram channel? python-telegram-bot 检查特定用户 ID 是否在语音通道中? - Check if Specific user id is in Voice Channel? 如何在 telethon 中离开带有 id 的频道或群组? - How to leave a channel or group with id in telethon? 从 Viber bot 向订阅用户发送消息 - Send message from Viber bot to subscribed user 如何使用 Telethon 获取电报私人频道 ID - How to get a telegram private channel id with telethon
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM