I made a bot that sends files from an external server with a URL.
I want the bot to send files directly from your server.
What am I doing wrong? Why didn't the open()
command work?
import telebot
bot = telebot.TeleBot("Token")
@bot.message_handler(commands=['start','help'])
def send_start_message(message):
bot.reply_to(message, "Hi.")
@bot.message_handler(func=lambda m: True)
def echo_all(message):
print(message.text)
duck = open('duck.png','r')
bot.send_photo(message.chat.id, duck)
bot.send_message(message.chat.id, "hi")
bot.polling()
You'll need to tell python3 to use binary mode;
duck = open('duck.png', 'rb')
Minimal working example to send local image:
import telebot
bot = telebot.TeleBot("<YOUR-TOKEN-HERE>")
cid = <YOUR-ID-HERE>
img = open('image.jpg', 'rb')
bot.send_photo(cid, img)