[Python] Could not find the input entity for PeerChannel

Discussão em 'Python' iniciado por Stack, Outubro 4, 2024.

  1. Stack

    Stack Membro Participativo

    I am using the telethon library to add any telegram channels to the database. Everything works fine when I add channels from my account, but other users cannot add a channel before I add it, they have the error Could not find the input entity for PeerChannel(channel_id=1234567890) (PeerChannel). Please read ... find out more details. After I add a channel that they couldn't add, they can add it. Why is this happening? Thanks in advance.

    async def get_channel_info(identifier: Union[int, str], info_client: TelegramClient, invite_link: bool) -> Optional[Tuple[str, Optional[str]]]:
    try:
    channel = await info_client.get_entity(identifier)
    title = channel.title
    username = getattr(channel, 'username', None)

    if invite_link and not username and getattr(channel, 'broadcast', False):
    try:
    peer_channel = InputPeerChannel(channel.id, channel.access_hash)
    invite = await info_client(ExportChatInviteRequest(peer_channel))
    return title, invite.link
    except ChatAdminRequiredError:
    pass
    except FloodWaitError as flood_wait:
    print(f"Error: You must wait {flood_wait.seconds} seconds before trying again.")
    except Exception as invite_error:
    print(f"Error when receiving invitation link: {invite_error}")

    link = f't.me/{username}' if username else None
    return title, link

    except Exception as e:
    print(f"Error: {e}")
    return None

    Continue reading...

Compartilhe esta Página