Jonny Shanahan
Jonny Shanahan

Reputation: 421

Telethon iter_messages works for one channel but not another

I have tried the following code which works for one channel but the other channel says "Could not find the input entity for PeerUser". Not sure why there's a difference. I think the channel still exists because when I open the channel in the browser (going to t.me/<channel_slug> and following the link), it sends me to the https://web.telegram.org/z address which has the same channel_id

messages_obj = client.iter_messages(int(channel_id))

any idea why this is?

Upvotes: 2

Views: 4152

Answers (1)

Jack
Jack

Reputation: 97

By this page you need some like this:

# (These examples assume you are inside an "async def")
async with client:
    # Does it have a username? Use it!
    user = await client.get_profile(username)

    # Do you have a conversation open with them? Get dialogs.
    await client.get_dialogs()

    # Are they participants of some group? Get them.
    await client.get_participants('username')

    # Is the user the original sender of a forwarded message? Fetch the message.
    await client.get_messages('username', 100)

    # NOW you can use the ID anywhere!
    await client.send_message(123456, 'Hi!')

    user = await client.get_profile(123456)
    print(user)

If you're here because of "Could not find the input peer for", you must ask yourself, "how did I find this user or chat through official applications"? Now do the same with the library.

So, I think that best way for you is the use string username. Or find workaround

Upvotes: 3

Related Questions