Answer the question
In order to leave comments, you need to log in
Is there a method to search for channels by keyword in telethon?
I want to write a telegram client that will search for channels using the search and read messages from them.
Reading messages I have already implemented. but I can’t find a method that would give me channel names (or id) by keyword.
Now it's like this:
from telethon import TelegramClient, connection
import socks
import asyncio
api_id = хххххх # API ID (obtained when registering the application on my.telegram.org)
api_hash = "ххххххххххххххххххх" # API Hash (from there)
# You must first log in to be file second_account created
# containing client authentication data.
proxy_ip="ххххх"
port=ххххх
client = TelegramClient('session4', api_id, api_hash, proxy=(socks.SOCKS5, str(proxy_ip), port),timeout=66)
client.start()
def readfromkanal():
kanal=input() # channel name for
loop = asyncio.get_event_loop() dp
= loop.run_until_complete(client.get_entity(kanal))
posts = loop.run_until_complete(client.get_messages(dp,limit=1000))
loop.close()
for post in posts:
print (post.message)
if __name__=="__main__":
readfromkanal()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question