A
A
avrovenskiy2022-04-10 22:45:24
Python
avrovenskiy, 2022-04-10 22:45:24

How to save a file sent to a chat bot to a specific folder on a PC?

When sending a File to a bot, it saves it not to the specified folder, but to the root of the project, and even empty

. Please see what's wrong?

@dp.message_handler(content_types=[types.ContentType.DOCUMENT])
async def scan_doc(message: types.document):
doc_name = message.document.file_name
await message.answer("Document loaded: " + doc_name)
await bot.download_file ("C:\\doki", doc_name)

625334139c850006336352.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2022-04-10
@SoreMix

https://docs.aiogram.dev/en/dev-3.x/api/download_f...
The first parameter is the path on the telegram server, the second is the file name. You have the first one - a folder with a PC, and the second one - a file name (not even a path) ps why is the type annotation made as if it is not a document that comes, but
await bot.download(message.document, 'C:\\file')
message: types.documentmessage

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question