3

I used to get the posts from a public telegram channel using telethon and everything works fine until today that the channel became private and although I am a subscriber to the channel I can not retrieve the channel messages with the message-id like before and I get an error that the channel is private and you can not access the messages. I should mention that I am a subscriber to the channel. I try different things and find out that telethon sign in as a bot and for that reason, the channel does not give it permission to read the channel messages. one other thing that I find out is that to make this work like before any bot should be added to the channel as an administrator to let telethon read messages like before. does anyone know any way to retrieve messages from a private channel that we are subscribed to without adding bot as an administrator to the channel?

client = TelegramClient('session', api_id, api_hash, proxy=("socks5", 'server', port))

# connecting and building the session
client.connect()


# in case of script ran first time it will
# ask either to input token or otp sent to
# number or sent or your telegram id
if not client.is_user_authorized():
    client.send_code_request(phone)

    # signing in the client
    client.sign_in(phone, input('Enter the code: '))

this is the way I use to sign in to my account but it signs in as a bot this way, is there any workaround not to sign in as a bot?

  • If you're a subscriber of the channel, you should be able to find it's `dialog.id` with `client.iter_dialogs`. Once you do that, use that `id`. – Lonami Feb 22 '21 at 18:00
  • I think something has changed in telegram API since I get the same error here as well: The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot (caused by GetDialogsRequest). --@Lonami – omid kiasat Feb 23 '21 at 19:50
  • I also face same issue, I need to retrieve the message body from a channel where saving and forwarding is disabled, and I'm only channel member, using telegram client – Navruzbek Noraliev Mar 21 '22 at 17:32
  • To get messages from private channels, you need a bot as a user. You can do this with [pyrogram](https://docs.pyrogram.org/). And If you use `numerical ID`, add `-100` prefix. – mo1ein Jul 16 '22 at 17:52

0 Answers0