Django电报机器人回复键盘无法正常工作

时间:2018-03-11 20:43:58

标签: django bots telegram

我有一个问题。我刚刚用django-telegram-bot package安装了Django 我使用示例中的函数,它基本上向用户返回一条消息。我想要的是向他发送一个reply_keyboard。这很奇怪,但它不起作用。这是我的代码:

from telegram.ext import CommandHandler, MessageHandler, Filters
from telegram import ReplyKeyboardMarkup, InlineKeyboardMarkup, 
InlineKeyboardButton
from django_telegrambot.apps import DjangoTelegramBot

def me(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)

    # THIS IS PRINTING  TEXT BUT Not keyboard!
    update.message.reply_text('Please choose:', 
    reply_markup=reply_markup)

    # Again sent text
    bot.sendMessage(update.message.chat_id, text='text works' ,reply_markup=markup)

这个问题我已经坚持了3天。

1 个答案:

答案 0 :(得分:0)

这对我有用

def echo(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)
    bot.sendMessage(update.message.chat_id, text=update.message.text,reply_markup=reply_markup)

你似乎在reply_markup=markup部分中犯了错误。