用户必须对照片进行评分,而评分后的机器人应在同一条消息中将照片更改为另一张照片。该机器人更改了一次图片,但随后给出了一个错误,指的是试图更改与过去相同的消息。
TeleBot:“对 Telegram API 的请求不成功。错误代码:400 描述:错误请求:消息未修改:指定的新消息内容和回复标记与消息的当前内容和回复标记完全相同”
@bot.message_handler(commands=["start"])
def any_msg(message):
keyboard = types.InlineKeyboardMarkup()
callback_button1 = types.InlineKeyboardButton(text="Одобряю", callback_data="poc")
callback_button2 = types.InlineKeyboardButton(text="Ме", callback_data="no_poc")
keyboard.row(callback_button1, callback_button2)
with open("test/bydlo.jpg", "rb") as image:
bot.send_photo(message.chat.id, image, reply_markup=keyboard)
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
if call.message:
if call.data == "no_poc" or "poc":
print("off")
keyboard = types.InlineKeyboardMarkup()
callback_button1 = types.InlineKeyboardButton(text="Класс", callback_data="anime")
callback_button2 = types.InlineKeyboardButton(text="Ме...", callback_data="non_anime")
keyboard.row(callback_button1, callback_button2)
with open("test/anime.jpg", "rb") as anime:
bot.edit_message_media(media=types.InputMedia(type='photo', media=anime),chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard)
elif call.data == "anime":
keyboard = types.InlineKeyboardMarkup()
callback_button2 = types.InlineKeyboardButton(text="Ме", callback_data="jeeraf")
callback_button1 = types.InlineKeyboardButton(text="Няяя", callback_data="very_anime")
keyboard.row(callback_button2, callback_button1)
with open("test/very_anime.jpg", "rb") as very_anime:
bot.edit_message_media(media=types.InputMedia(type='photo', media=very_anime), chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=keyboard)
在您检查 call.data 的第二个回调处理程序中出现错误
if call.data == "no_poc" or "poc":
。事实是 Python 在这种情况下总是会返回 True ,因为它将这个表达式拆分为call.data == "no_poc"
and"poc"
。第一个可能并不总是 true,但第二个总是返回 True。在这种情况下,我会像这样检查这个条件: