Answer the question
In order to leave comments, you need to log in
How to get picture from telegram bot?
Hello everyone, can you please tell me how to get the picture that the user sent to the bot, and then send it to another group?
In general, I do this:
@bot.message_handler(content_types=["text", "sticker", "pinned_message", "photo", "audio"])
def echo_msg(message):
if message.content_type == 'text':
bot.send_message(chatID, "Запрос от\n*{name} {last}*\n{text}".format(name=message.chat.first_name, last=message.chat.last_name, text=message.text), parse_mode="Markdown") #от кого идет сообщение и его содержание
bot.send_message(message.chat.id, "*{name}!*\n\nСпасибо за инфу".format(name=message.chat.first_name, last=message.chat.last_name, text=message.text), parse_mode="Markdown") #то что пойдет юзеру после отправки сообщения
elif message.content_type == 'photo':
bot.send_message(chatID, "Запрос от\n*{name} {last}*\n{photo}".format(name=message.chat.first_name, last=message.chat.last_name, photo=message.photo), parse_mode="Markdown") #от кого идет сообщение и его содержание
bot.send_message(message.chat.id, "*{name}!*\n\nСпасибо за инфу".format(name=message.chat.first_name, last=message.chat.last_name, text=message.text), parse_mode="Markdown") #то что пойдет юзеру после отправки сообщения
<telebot.types.PhotoSize instance at 0x7fe4fef8d368>, <telebot.types.PhotoSize instance at 0x7fe4fef8d3f8>, <telebot.types.PhotoSize instance at 0x7fe4fef8d3b0>, <telebot.types.PhotoSize instance at 0x7fe4fef8d680>
Answer the question
In order to leave comments, you need to log in
RESOLVED.
Changed the code:
elif message.content_type == 'photo':
raw = message.photo[2].file_id
name = raw+".jpg"
file_info = bot.get_file(raw)
downloaded_file = bot.download_file(file_info.file_path)
with open(name,'wb') as new_file:
new_file.write(downloaded_file)
img = open(name, 'rb')
bot.send_message(chatID, "Запрос от\n*{name} {last}*".format(name=message.chat.first_name, last=message.chat.last_name), parse_mode="Markdown") #от кого идет сообщение и его содержание
bot.send_photo(chatID, img)
bot.send_message(message.chat.id, "*{name}!*\n\nСпасибо за инфу".format(name=message.chat.first_name, last=message.chat.last_name, text=message.text), parse_mode="Markdown") #то что пойдет юзеру после отправки сообщения
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question