Answer the question
In order to leave comments, you need to log in
How to accept a photo from a user in a telegram bot?
there is such a code but it writes an error like there is no file_id
@bot.message_handler(content_types=['photo'])
try:
chat_id = message.chat.id
file_info = bot.get_file(message.document.file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = 'C:/Users/Timur/PycharmProjects/waltermark/documents/' + message.document.file_name;
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
bot.reply_to(message, "Пожалуй, я сохраню это")
except Exception as e:
bot.reply_to(message, e)
Answer the question
In order to leave comments, you need to log in
@bot.message_handler(content_types=['photo'])
try:
file_info = bot.get_file(message.photo[len(message.photo) - 1].file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = 'C:/Users/Timur/PycharmProjects/waltermark/documents/' + message.document.file_name;
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
bot.reply_to(message, "Пожалуй, я сохраню это")
except Exception as e:
bot.reply_to(message, e)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question