skip to Main Content

python version 3.8.3

import telegram #imorted methodts
from telegram.ext import Updater, CommandHandler
import requests
from telegram import ReplyKeyboardMarkup, KeyboardButton 
from telegram.ext.messagehandler import MessageHandler
import json

# below is function defined the buttons to be return
def start(bot, update):
 button1 = KeyboardButton("hello")
 button2 = KeyboardButton("by")
 keyboard = [button1, button2] 
 reply_markup = telegram.ReplyKeyboardMarkup(keyboard)
 chat_id = update.message.chat_id
 bot.send_message(chat_id=chat_id, text='please choose USD or EUR', reply_markup = reply_markup) # it works and returns text if reply_markup parameter disabled.

def main(): 
 updater = Updater('my token')
 dp = updater.dispatcher
 dp.add_handler(CommandHandler('start', start))
 updater.start_polling()
 updater.idle()

main()

buttons are not working. Please help to check what could be the reason of this issue.

2

Answers


  1. try using string instead of keyboard button:

    def start(bot, update):
     keyboard = [["USD", "EUR"]]
     reply_markup = telegram.ReplyKeyboardMarkup(keyboard)
     chat_id = update.message.chat_id
     bot.send_message(chat_id=chat_id, text='please choose USD or EUR', reply_markup = reply_markup)
    
    def main(): 
     updater = Updater('my token')
     dp = updater.dispatcher
     dp.add_handler(CommandHandler('start', start))
     updater.start_polling()
     updater.idle()
    
    main()
    
    Login or Signup to reply.
  2. Add logging, so you’ll be able to see if there are any errors or response with error there.

    import logging
    
    logger = logging.getLogger(__name__)
    logging.basicConfig(level=logging.DEBUG)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search