`from telethon.sync import TelegramClient, events
import os
import random
import time
print(‘User-Bot started’)
api_id = api hash
api_hash = ‘api id’
with TelegramClient(‘anonimal’, api_id, api_hash) as client:
while True:
mem = open(‘C:/fg/spam/members.csv’) # I take the ID of the chat from the members.csv file
-100972139773
line = mem.readline()
print(line)
client.send_message(line, ‘hello chat’)
print(‘message send’)
client.run_until_disconnected()`
Error:
Traceback (most recent call last): File "C:UsersdragoAppDataLocalProgramsPythonPython310crash.py", line 21, in <module> client.send_message(line, 'Сколько стоит переносной ларек?') File "C:UsersdragoAppDataLocalProgramsPythonPython310libsite-packagestelethonsync.py", line 39, in syncified return loop.run_until_complete(coro) File "C:UsersdragoAppDataLocalProgramsPythonPython310libasynciobase_events.py", line 649, in run_until_complete return future.result() File "C:UsersdragoAppDataLocalProgramsPythonPython310libsite-packagestelethonclientmessages.py", line 838, in send_message entity = await self.get_input_entity(entity) File "C:UsersdragoAppDataLocalProgramsPythonPython310libsite-packagestelethonclientusers.py", line 438, in get_input_entity await self._get_entity_from_string(peer)) File "C:UsersdragoAppDataLocalProgramsPythonPython310libsite-packagestelethonclientusers.py", line 575, in _get_entity_from_string raise ValueError( ValueError: Cannot find any entity corresponding to "-100972139773"
after entering the data, this error occurs
2
Answers
You need to save it in the cache before use , or use a username instead, btw user_id must be int
In my understanding, this happens in case your account is not a member of the channel, so please check that account you are using is a member of the channel of your interest. Also, using
with client
andwhile True
is considered a bad practice, please read doc and use the more appropriate approach if you want to listen to something indefently:and don’t forget to disconnect when you are done, using: