I’m using Telethon’s send_message function to send messages to various numbers.
Problem that I’m facing is I can send messages to numbers that are in my contact list, but when I’m sending message to unsaved number I’m getting an error "ValueError: Cannot find any entity corresponding to "+XXXXXXXXXXXX"
from telethon import TelegramClient
api_id = xxxxx
api_hash = 'xxxxx'
client = TelegramClient('anon', api_id, api_hash)
async def main():
await client.send_message('+XYZXYZXYZXYZ', 'Hello, friend!')
with client:
client.loop.run_until_complete(main())
3
Answers
None of the above answer works for me so after lot of effort I got the solution of the problem. It is not possible to send message to a telegram user without saving their number. To overcome this problem first we have to save the number by these lines of code:
Note: You have to downgrade your telethon to 0.19 for this just run pip install telethon==0.19
Here is full working code:
it’s the new telegram limit about get numbers of accounts
if it’s
Nobody
you can’t find it by number if you have not this in your contacts beforeFirst you need to make telethon aware of all the entities at least once:
For this use:
After this get the entity represented by the mobile number using the command:
Now you can use the entity to send message
For more info have a look at this : Telethon Entities