我正在编写一个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_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 set command to mbti并将其传递给命令处理程序时,当命令处理程序获得mbti命令时,启动运行starx函数。
但是当我在if条件中使用下面的代码时,它会在检查if条件之前发送它
updater.dispatcher.add_handler (CommandHandler (command = command , startx)在这种情况下我应该怎么做?
发布于 2017-09-18 02:14:01
使用ConversationHandler显示深层交互式菜单。另一种方式可以存储状态,并使用userState调用函数。
有关更多信息,请参阅docs example,它还支持user_data和RegExp,以便强大地处理来自用户的消息。
不要忘记:数据存储在内存中,在某些情况下,您可能丢失或不正确。很好,在入口点清理了user_data,
每个函数可以有多个returns指向其他条目和另一边-每个条目在不同的匹配大小写下有许多不同的函数。
https://stackoverflow.com/questions/45546250
复制相似问题