'How does file_id use in telethon to send a file by a bot?

To not re-download the file again, I want to send its file_id obtained from a previously sent message.

How does file_id use in telethon to send a file by a bot (not a client):

async def main():
    t_client = TelegramClient(TG_APP_TITLE, TG_APP_ID, TG_API_HASH)
    await t_client.connect()
    if not await t_client.is_user_authorized():
        await t_client.send_code_request(TG_PHONE)
        await t_client.sign_in(code=input('Get code:'))

    t_bot = TelegramClient(f'{TG_APP_TITLE}Bot', TG_APP_ID, TG_API_HASH)
    a_bot = aiogram.Bot(TG_BOT_API_TOKEN)

    await t_client.start()
    await t_bot.start(bot_token=TG_BOT_API_TOKEN)

    r = await t_client.send_file(TG_BOT, 'podcasts/gnj2_SB0MOM.100.96.mp3')
    file_id = pack_bot_file_id(r.media)

    await t_client.send_file(TG_CHAT_ID, file_id)  # Correct
    await a_bot.send_audio(TG_CHAT_ID, file_id)  # Correct
    await t_bot.send_file(TG_CHAT_ID, file_id)  # Error

When I am trying to send file_id by bot

await t_bot.send_file(TG_USER, file_id)

Traceback (most recent call last):
  File "C:/Users/Alexo/PycharmProjects/personal/TGVideoToPodcastBot/temp.py", line 76, in main
    await t_bot.send_file(TG_CHAT_ID, file_id)  # Error
  File "C:\Python39\lib\site-packages\telethon\client\uploads.py", line 381, in send_file
    return self._get_response_message(request, await self(request), entity)
  File "C:\Python39\lib\site-packages\telethon\client\users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "C:\Python39\lib\site-packages\telethon\client\users.py", line 79, in _call
    result = await future
telethon.errors.rpcerrorlist.MediaEmptyError: The provided media object is invalid or the current account may not be able to send it (such as games as users) (caused by SendMediaRequest)

If I send the file_id through the Bot API (a_bot) or by the client (t_client), then everything is fine.



Solution 1:[1]

from telethon.tl.types import InputDocument        
doc = InputDocument(yorfile.id, yorfile.access_hash, yorfile.file_reference)
await client.send_file("@onetimeusername", doc)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Maksi_mak2