Hi can’t figure out how to solve this problem, so any help will be really appreciated.
I’m subscribed to a private channel. This channel has no username and I don’t have the invite link (the admin just added me).
Since I use this channel at work, to speed up the things I want to process the messages posted on the channel using Telethon.
The core of the program is:
@events.register(events.NewMessage(chats = my_private_channel))
async def handler(event):
#do things
The problem is that I am not able to filter the messages coming to that specific channel id. I get the error:
ValueError: Cannot find any entity corresponding to "0123456789"
I have tried different technique to obtain my channel Id but the error is always the same. In particular:
- The channel is private so it has no username ("@blablabla")
- I have no invite link
- I have tried to process all incoming messages until the admin sent a message on the channel, print sender information and get the value from the "ID" key
- I have tried to use telegram web and get the ID from the url (also adding -100 in front of it)
But when I put the ID in the parameter chats, I get always the error reported above.
Thanks in advance,
Have a nice day
3
Answers
You can’t join a private channel without the invite link, nor can you get any information about it. It’s private, as the name implies.
if you have access to the channel, then it’s shown in your chat list.
You have to loop through your chats checking their titles and then store the desired chat in a variable:
Than you can filter messages sent to my_private_channel.
You can print all the dialogs/conversations that you are part of.
also you need to remove -100 prefix from the id you got like:
-1001419092328 = 1419092328 (actual ID)
if you want to listen to a specific channel, you can use
channel_id=1419092328
. you will only receive messages that are broadcasted to it: