如何在使用InlineKeyboard Python-Telearm-Bot时编辑/删除消息 [英] How To Edit / Delete Message While Using InlineKeyboard Python-Telegarm-Bot
本文介绍了如何在使用InlineKeyboard Python-Telearm-Bot时编辑/删除消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何添加串联键盘:
@run_async
def help(update, context):
text = Translation.HELP_TEXT,
update.effective_message.reply_text(text=text,
# parse_mode=ParseMode.HTML,
reply_markup=InlineKeyboardMarkup(
[[ InlineKeyboardButton('⚡Home⚡', callback_data='start_button'),
InlineKeyboardButton('Donate💸', callback_data='upgrade_button')
],
[ InlineKeyboardButton('About🛑', callback_data='about_button')
]]
)
)
@run_async
def about(update, context):
text = Translation.ABOUT_TEXT,
update.effective_message.reply_text(text=text,
# parse_mode=ParseMode.HTML,
reply_markup=InlineKeyboardMarkup(
[[ InlineKeyboardButton('⚡Home⚡', callback_data='start_button'),
InlineKeyboardButton('⚙ Help', callback_data='help_button')
],
[ InlineKeyboardButton('Close🔐', callback_data='cancel_btn')
]]
)
)
我如何添加回调:
def main():
fs_utils.start_cleanup()
help_handler = CommandHandler(BotCommands.HelpCommand, help)
about_handler = CommandHandler(BotCommands.AboutCommand, about)
#Callback
#
#
#
#
start_callback = CallbackQueryHandler(start, pattern='start_button')
about_callback = CallbackQueryHandler(about, pattern='about_button')
upgrade_callback = CallbackQueryHandler(upgrade, pattern='upgrade_button')
help_callback = CallbackQueryHandler(help, pattern='help_button')
#
#Dispatcher
#
#
#
dispatcher.add_handler(about_handler)
dispatcher.add_handler(help_handler)
#callback
#
#
#
#
dispatcher.add_handler(start_callback)
dispatcher.add_handler(help_callback)
dispatcher.add_handler(about_callback)
dispatcher.add_handler(upgrade_callback)
#
#
#
#
#
updater.start_polling()
LOGGER.info("Bot Started Sucessfully!")
signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
main()
推荐答案
而不是update.effective_message.reply_text
,使用update.callback_query.edit_text
edit_text
方法将编辑已发送消息的文本和回复标记
而reply_text
发送新消息。
用法示例:
update.callback_query.edit_text(text=text,
# parse_mode=ParseMode.HTML,
reply_markup=InlineKeyboardMarkup(
[[ InlineKeyboardButton('⚡Home⚡', callback_data='start_button'),
InlineKeyboardButton('⚙ Help', callback_data='help_button')
],
[ InlineKeyboardButton('Close🔐', callback_data='cancel_btn')
]]
)
)
参考文档here
这篇关于如何在使用InlineKeyboard Python-Telearm-Bot时编辑/删除消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文