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

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

通过我的电报机器人,我必须检查给机器人发短信的用户是否在我的电报频道中, 我试过了:

        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

它只适用于我的本地主机,但在我的 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.

我已经阅读了 entities.html 所提到的,但没有任何效果。

我也试过:

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

但我一直收到 TypeError: argument of type 'ChannelParticipants' is not iterable

事实证明,我必须 re-add 我的机器人到频道,因为当我将它移动到另一台设备时,机器人丢失了对频道的访问哈希,因为访问哈希存储在 .session 文件,传输后丢失。