如何解决python电报机器人API中的updater.dispatcher.add_hanlder
我正在写一个python电报机器人,我想使用内联键盘底部。 我把这段代码写在下面:如何解决python电报机器人API中的updater.dispatcher.add_hanlder,python,python-3.x,telegram,telegram-bot,python-telegram-bot,Python,Python 3.x,Telegram,Telegram Bot,Python Telegram Bot,我正在写一个python电报机器人,我想使用内联键盘底部。 我把这段代码写在下面: from telegram import * from telegram.ext import * mbti_message = 'This is a test massage that should sent in MBTI part' def startx(bot, update): keyboard = [[InlineKeyboardButton("Option 1", callback_dat
from telegram import *
from telegram.ext import *
mbti_message = 'This is a test massage that should sent in MBTI part'
def startx(bot, update):
keyboard = [[InlineKeyboardButton("Option 1", callback_data='1'),
InlineKeyboardButton("Option 2", callback_data='2')],
[InlineKeyboardButton("Option 3", callback_data='3')]]
reply_markup = InlineKeyboardMarkup(keyboard)
chat_id = update.message.chat_id
bot.sendMessage(chat_id, "Message Sent From Function STARTX", reply_markup=reply_markup)
def buttomx(bot, update):
query = update.callback_query
bot.edit_message_text(text="Selected option: %s" % query.data,
chat_id=query.message.chat_id,
message_id=query.message.message_id)
def start (bot,update):
keyboard_list = [[InlineKeyboardButton("ABOUT US", callback_data='1')],
[InlineKeyboardButton("MBTI Test Start", callback_data='2')]]
reply_markup = InlineKeyboardMarkup(keyboard_list)
chat_id = update.message.chat_id
start_message_sent = "Welcome To My Bot Please Chose Your Options"
bot.sendMessage(chat_id,start_message_sent, reply_markup=reply_markup)
bot.sendMessage(chat_id,start_message_sent_global,reply_markup=reply_markup)
def bottom(bot, update):
counter = 0
query = update.callback_query
chat_id = query.message.chat_id
selected_option = int(query.data)
if selected_option==1 :
bot.sendMessage(chat_id,"You Chose About Us Section Thanks For Choosing Us")
elif selected_option==2:
bot.sendMessage(chat_id,"You Are Ready To Start Test ...")
command = 'mbti'
updater.dispatcher.add_handler(CommandHandler(command=command, callback=startx))
updater.dispatcher.add_handler(CallbackQueryHandler(buttomx))
updater.start_polling()
当用户按下底部MBTI时,将命令设置为MBTI并将其传递给命令处理程序,当命令处理程序获取MBTI时,命令开始运行starx函数
但是当我在if条件下使用下面的代码时,它会在检查if条件之前发送它
updater.dispatcher.add_handler (CommandHandler (command = command , startx)
在这种情况下,我应该怎么做?使用
会话处理程序
进行深度交互菜单。另一种方法是存储userState,并使用State调用函数
有关更多信息,请参阅它还支持的文档user\u data
和RegExp,以强大地处理来自用户的消息
不要忘记:数据存储在内存中,在某些情况下可能丢失或不正确。很好,在入口点清理了用户\u数据
每个函数可以有许多
返回
到另一个条目和另一方-每个条目在不同的匹配情况下有许多不同的函数。您正在添加一个处理程序以响应某些更新。add\u处理程序
调用只能在底部之外执行一次
command@balki我知道了,但如果我想当用户按下某个底部按钮并运行某个函数时,我应该怎么做?