【问题标题】:Python-Telegram-Bot ConversationHandler unable to receive MessagePython-Telegram-Bot ConversationHandler 无法接收消息
【发布时间】:2021-12-08 03:26:47
【问题描述】:

我正在使用 Python-Telegram-Bot 包。我的电报机器人无法接收状态为FIRST 的消息。发送我的机器人/start 后,我会收到start_command 中所示的短信提示。但是,在向机器人发送 url 后,机器人无法接收消息,如我的消息右下角的“单勾”所示。

# Stages
FIRST, SECOND = range(2)

def start_command(update: Update, context: CallbackContext):
    update.message.reply_text("""
To use: 
1. Send the google sheets URL and sheet name to this telegram bot in the following format:
your_google_sheets_url (your_sheet_name)
""")
    global user_id
    user_id = update.message.from_user['id']

    return FIRST


def select(update: Update, context: CallbackContext):
    if update.message.text:
        user_input = update.message.text
        update.message.reply_text('I have received your Google Sheets!')
    reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=1))
    update.message.reply_text('Please choose the headers:', reply_markup=reply_markup)

    return SECOND
    dp = updater.dispatcher
    dp.add_handler(CommandHandler("start", start_command))
    conv_handler = ConversationHandler(
        entry_points=[CommandHandler('start', start_command)],
        states={
            FIRST: [MessageHandler(Filters.text, select)],
            SECOND: [CallbackQueryHandler(display)],
        },
        fallbacks=[CommandHandler('cancel', cancel)],
    )
    dp.add_handler(conv_handler)

【问题讨论】:

  • 您需要首先澄清一些事情,例如您正在使用哪个 telegram Bot 包,然后添加您的错误以及更多关于问题的上下文。
  • @SumitJaiswal 谢谢。

标签: telegram telegram-bot python-telegram-bot


【解决方案1】:

不应添加 startCommandHandler。这是因为当用户输入/start时,会调用CommandHandler而不是ConversationHandler来处理命令。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    • 2020-07-16
    • 2020-09-26
    • 2019-03-09
    相关资源
    最近更新 更多