Helio Junior
Helio Junior

Reputation: 163

How to fix the Telethon's exception BadMessageError

I'm doing an application to download all files form a Telegram channel. When downloading I receive the error message:

telethon.errors.rpcbaseerrors.BadMessageError: Message too old, and it cannot be verified 
whether the server has received a message with this msg_id or not.

Anyone know how to fix this?

Upvotes: 0

Views: 448

Answers (1)

Alihossein shahabi
Alihossein shahabi

Reputation: 4352

I test and download all files by this code and it was fine. (such as Fundamentos_de_Matemática_Elementar.pdf)

from telethon import TelegramClient

api_id = XXXXX
api_hash = 'a191b0c8c7d88a1c34XXXXXXXXXXXXX'
phone_number = '+98937XXXXXXXX'
######################t##########################
channel_username = 'matematicaEmPDF'
################################################

client = TelegramClient(phone_number,
                    api_id,
                    api_hash,        
        )

client.start(phone=phone_number)

# ---------------------------------------
msgs = client.get_messages(channel_username, limit=100)

for msg in msgs.data:
    if msg.media is not None:
        client.download_media(message=msg)

Upvotes: 1

Related Questions