skip to Main Content

stackoverflow. I beginer python developter and need help.
I want download foto on my serwer from different telegram chenals. Have htis code, but it download all media including video. How i can chenge code to download only photo? I’ve read the documentation, but don’t found the answer. Thank you!

from telethon.sync import TelegramClient, events
from telethon.tl.functions.messages import GetDialogsRequest
from tqdm import tqdm

with TelegramClient('name', api_id, api_hash) as client:
    result = client(GetDialogsRequest(
        offset_date=None,
        offset_id=0,
        offset_peer="username",
        limit=500,
        hash=0,
    ))

    title = 'Новинки Margaret❤'
    for chat in result.chats:
        print(chat)

        if chat.title == title:
            messages = client.get_messages(chat, limit=1000)

            for message in tqdm(messages):
                message.download_media('./' + title + '/') #I think the problem is right here.

2

Answers


  1. Chosen as BEST ANSWER

    I added a file check. This solved my problem.

      for message in tqdm(messages):
            if type(message.media) == telethon.MessageMediaPhoto: 
                message.download_media('./' + title + '/')
    

  2. Good Morning, I try to help you.

    I think your problem is how do you read the line:

    message.download_media('./' + title + '/')
    

    Think that in the Telethon documentation it is shown as follows:

    client.download_media(media, path)
    

    I have found a similar bug, try from this already solved question:

    All credits to the user who solved it

    Have a great day!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search