I'm using Telethon's send_message function to send messages to various chats.
Sometimes, the destination is another user (just a regular one on one chat), sometimes a group, sometimes a supergroup, and sometimes a channel (of which I'm admin).
If I understand correctly, the syntax is supposed to be:
client.send_message(entity,text)
But I can't figure out what the entity
parameter is supposed to be in different cases. What I find especially confusing is specifying an integer id seems to work fine for some groups, but not for others.
For example:
I have a normal 1-to-1 chat with someone who has user_id 11111
, and also with another person who has user_id 22222
.
Furthermore I'm in two groups (supergroups actually) which have channel_id 33333
and 44444
.
I can specify 11111
or 33333
as entity, and the message gets sent correctly (to the first person or the first group respectively). However if I specify 22222
or 44444
, I'm getting an error:
Cannot find any entity corresponding to "{}"'.format(string)
ValueError: Cannot find any entity corresponding to "22222"
I am also receiving mesasges from all 4 chats using this same Telethon instance, and that's working all fine.
So my question is: how do I get the correct entity data for send_message()?
client.send_message(PeerUser(user_id=11111), 'test-message')
, where11111
is chat_id you send message to, also add linefrom telethon.tl.types import PeerUser
. – Practicable