Reputation: 43
Having troubles with sending image with text. Instead of actual image, I'm just getting the path to it. I wonder if someone knows what is the problem in my code. Instead of the path I want an actual image
import telebot
from telebot import types
bot = telebot.TeleBot("token")
@bot.message_handler(commands = ['start'])
def button(message):
markup = types.InlineKeyboardMarkup(row_width=2)
item_4 = types.InlineKeyboardButton('q1', callback_data ='da')
item_3 = types.InlineKeyboardButton("asdas", callback_data = 'net')
markup.add(item_4, item_3)
img = r'C:\Python\k123s.jpg'
text = 'Your profile!'
bot.send_message(message.chat.id, f'{text}\n{img}', reply_markup = markup)
Upvotes: 1
Views: 4421
Reputation: 11
Instead of send_message
you need to use send_photo
.
In your case, the last 3 lines will be:
img = r'C:\Python\k123s.jpg'
text = 'Your profile!'
bot.send_photo(message.chat.id, photo=open(img, 'rb'), caption=text, reply_markup = markup)
Upvotes: 1
Reputation: 43
I found the solution:
import telebot
from telebot import types
bot = telebot.TeleBot("token")
@bot.message_handler(commands = ['start'])
def button(message):
markup = types.InlineKeyboardMarkup(row_width=2)
item_4 = types.InlineKeyboardButton('q1', callback_data ='da')
item_3 = types.InlineKeyboardButton("asdas", callback_data = 'net')
markup.add(item_4, item_3)
#img = r'C:\Python\k123s.jpg'
#text = 'Your profile!'
bot.send_message(message.chat.id, open=(r'C:\Python\k123s.jpg', 'rb'), caption="text", reply_markup = markup)
PyTelegramBotApi has captions, which lets you add text to photos caption = 'text'
Upvotes: 1