1

I am trying to retrieve message from a private Telegram channel. I am the member of the channel and I can see the messages both on Telegram app and Telegram Web.

I tried the following code which works as expected and prints messages for non-private channels. However, when I input the name/ID of the private channel the output is an empty string.

Is this due to the issue in the code, or it is not possible to access private messages through Telethon?

Thank you.

async with client:
    async for msg in client.iter_messages(client ID integer not string, 5):
        print(msg.text)
CallMeStag
  • 5,467
  • 1
  • 7
  • 22

2 Answers2

0

It is possible to get messages from private channels with client bot (like real user) not chat bot.
If you use numerical ID, add -100 prefix. Check this answer.

mo1ein
  • 535
  • 4
  • 18
0

I was just searching for my problem and i had your problem yesterday! So the point is that every channel or chat has type. So for channel you can use function like this

PeerChannel

and inner argument should be a channel_id with the specific id that you are going to search!

async for i in client.iter_messages(PeerChannel(channel_id="your channel id")):
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Mohamad Sh
  • 41
  • 5