Answer the question
In order to leave comments, you need to log in
The bot sends a photo from the directory to the chat, how can I get the file_id so that it does not load every time from the folder?
There is a code that catches the photos sent to the bot, and I can get the file_id this way, but it does not work when the bot itself sends the photo
@dp.message_handler(content_types=['photo'], state='*')
async def scan_photo(message: types.Message):
doc = message.photo[0].file_id
info = await bot.get_file(doc)
Answer the question
In order to leave comments, you need to log in
photo_data = await db.get_file_info(f'{files_dir}file_name.png')
if photo_data is None:
media = types.InputFile(f'{files_dir}file_name.png')
msg = await dp.bot.send_photo(chat_id=message.chat.id, photo=media)
full_size_photo_id = msg['photo'][-1]['file_id']
await db.add_file_info(full_size_photo_id)
else:
await dp.bot.send_photo(chat_id=message.chat.id, photo=photo_data)
if photo_data is None:
if len(photo_data) == 0:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question