![](/img/trans.png)
[英]Get the text of a message known the message identifier (chat_id, message_id) with telepot
[英]how to get chat_id and message_id in telebot(pytelegramBotAPI) to update last sent message in telegram bot(Python)
这是我的代码
bot.edit_message_text(chat_id = CHAT_ID, message_id = MESSAGE_ID, text = "message has been updated", reply_markup=inline_keyboard)
我认为您可以通过以下方式获得它:
lastMessageId = message[-1].message_id
lastChatId = message[-1].chat.id
我不知道为什么需要它,但我通过示例向您了解如何使用消息ID和用户ID。
您应该创建一个键盘:
keyboard = types.InlineKeyboardMarkup()
keyboard.add(types.InlineKeyboardButton('Yes', callback_data='yes'),
types.InlineKeyboardButton('No', callback_data='no'))
创建一个命令:
@bot.message_handler(commands=['like'])
def like(message):
cid = message.chat.id
bot.send_message(cid, "Do you like it?", reply_markup=keyboard)
创建回调:
@bot.callback_query_handler(func=lambda call: call.data in ['yes', 'no'])
def callback_handler(call):
cid = call.message.chat.id
mid = call.message.message_id
answer = call.data
update_lang(cid, answer)
try:
bot.edit_message_text("You voted: " + answer, cid, mid, reply_markup=keyboard)
except:
pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.