Answer the question
In order to leave comments, you need to log in
Reply sending files to Telebot?
I am writing a Telegram bot in Python using the PyTelegramBotApi library, or Telebot. I need to implement an echo bot, but only with files or photos, for example:
/start command, upload a photo, the bot sends it back to you. Is it possible to do so? I didn't find it in the documentation. Here's everything there is so far:
import telebot
bot = telebot.TeleBot("...")
@bot.message_handler(commands=["start"])
def send(message):
bot.send_message(message.chat.id, "Текст, документ или фото для отправки.")
@bot.message_handler(content_types=["text", "document", "photo"])
def send_to_channel(message):
try:
bot.send_message(message.chat.id, message.text)
except:
try:
bot.send_photo(message.cht.id, #отправка фото)
except:
bot.send_document(message.chat.id, #отправка документа)
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
I'll leave a link to stackoverflow. It tells how to save the received photo
https://ru.stackoverflow.com/questions/615733/Save...
And in order to send a photo, you must first open it, and then send it via bot.send_photo():
with open("путь к файлу", "rb") as photo:
bot.send_photo(message.chat.id, photo)
with open("addQuestion.png", "rb") as photo:
bot.send_photo(message.chat.id, photo)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question