文本+图像不适用于电报机器人
Text + image not working with telegram bot
发送带文字的图片时遇到问题。而不是实际图像,我只是得到它的路径。我想知道是否有人知道我的代码中有什么问题。我想要一个实际图像而不是路径
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)
我找到了解决方案:
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 有标题,可让您向照片添加文字caption = 'text'
发送带文字的图片时遇到问题。而不是实际图像,我只是得到它的路径。我想知道是否有人知道我的代码中有什么问题。我想要一个实际图像而不是路径
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)
我找到了解决方案:
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 有标题,可让您向照片添加文字caption = 'text'