'disable reusing same file_id for media

is there a way to disable reusing file_id for media? since it's lookup on database and I want media reuploaded every time

I use copy message client.send_meesage on telethon and it's still looks up for file_id of image or video on database

i'm looking to make telethon to upload media instead of reuse file_id from database as client.send_file can be done with allow_cache=False

I looked on docs, couldn't find anything related, and seem allow_cache=False not works with client.send_meesage



Solution 1:[1]

You can use telethon.sessions.string.StringSession, this doesn't cache any data.

But probably you still want to cache the entities, so you can create your own class that inherits from one telethon.sessions.sqlite.SQLiteSession or telethon.sessions.memory.MemorySession, override the get_file method and make this returns always None. If you don't want to cache the files neither, must override cache_file method and make this just pass.

from telethon import TelegramClient
from telethon.sessions import SQLiteSession

class NoFilesSession(SQLiteSession):

    def get_file(self):
        pass

    def cache_file(self):
        pass

client = TelegramClient(NoFilesSession('client'), API_ID, API_HASH)

This new session will mock the function client.send_message, making it trust that there are no matches in the cache.

I recommend you to dive in the telethon.sessions package source code and the documentation for the default types of sessions.

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