Text + image not working with telegram bot

Question:

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

enter image description here

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:Pythonk123s.jpg'
    text = 'Your profile!'

    bot.send_message(message.chat.id, f'{text}n{img}', reply_markup = markup)
Asked By: CrazyChaos

||

Answers:

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:Pythonk123s.jpg'
    #text = 'Your profile!'

    bot.send_message(message.chat.id, open=(r'C:Pythonk123s.jpg', 'rb'), caption="text", reply_markup = markup)

PyTelegramBotApi has captions, which lets you add text to photos caption = 'text'

Answered By: CrazyChaos

Instead of send_message you need to use send_photo.
In your case, the last 3 lines will be:

img = r'C:Pythonk123s.jpg'
text = 'Your profile!'
bot.send_photo(message.chat.id, photo=open(img, 'rb'), caption=text, reply_markup = markup)
              
                
Answered By: Dovahkkin