I need my bot to save photos to my computer, where it is running, to a specified path. The function for this:
const fs = require('fs');
const path = require('path');
...
bot.on('photo', (msg) => {
const chatId = msg.chat.id;
const photo = msg.photo[0];
const fileId = photo.file_id;
const fileName = `${chatId}.jpg`;
const filePath = `D:/bot/${fileName}`;
bot.downloadFile(fileId, filePath)
.then(() => {
bot.sendMessage(chatId, 'Done!');
})
.catch((downloadErr) => {
console.error('Error downloading photo:', downloadErr);
bot.sendMessage(chatId, 'Error while saving.');
});
});
I get an error
Error downloading photo: [Error: ENOENT: no such file or directory, open 'D:\bot\248408814.jpg\file_12.jpg']
Why does he leave the name of the file it downloads from telegram? I want the photo to be in this file path: 'D:\bot\248408814.jpg'