Python бот telegram не выполняет действия действий - PullRequest
2 голосов
/ 30 января 2020

Я сделал этот код для отображения кнопок на /start.

from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, ConversationHandler
MENU, HELP = range(2)

def start(bot, update):
    keyboard = [
                 [InlineKeyboardButton('Help', callback_data='help')]
               ]

    # Create initial message:
    message = 'Welcome.'

    update.message.reply_text(message, reply_markup=InlineKeyboardMarkup(keyboard))

def help(bot, update):

    keyboard = [
                 [InlineKeyboardButton('Leave', callback_data='cancel')]
               ]


    bot.edit_message_text(
    text='Help ... help..',
    chat_id=update.callback_query.message.chat_id,
    message_id=update.callback_query.message.message_id,
    reply_markup=InlineKeyboardMarkup(keyboard)
)
    bot.answer_callback_query(update.callback_query.id, text='')

def cancel(bot, update):

    bot.edit_message_text(
    text='Bye',
    chat_id=update.callback_query.message.chat_id,
    message_id=update.callback_query.message.message_id,
)
    bot.answer_callback_query(update.callback_query.id, text='')

    return ConversationHandler.END     


# Create the EventHandler and pass it your bot's token.
updater = Updater(token="tokencode", use_context=True)

# Get the dispatcher to register handlers:
dispatcher = updater.dispatcher

dispatcher.add_handler(CommandHandler('start', start))
dispatcher.add_handler(CallbackQueryHandler(help, pattern='help'))
dispatcher.add_handler(CallbackQueryHandler(cancel, pattern='cancel'))

updater.start_polling()

updater.idle()

Код работает, потому что если мы напишем некоторую отладочную печать ("привет") в методах и мы выполним бот, мы увидим, что мы вводим в эти методы. Тем не менее кнопки или сообщения не отображаются.

Результат кода должен быть таким, но не работает так https://i.stack.imgur.com/c0wyM.gif

I Занимаюсь этим уже много часов, поэтому любая помощь приветствуется.

...