首页 > 解决方案 > 电报自定义键盘按钮不起作用。执行后,电报中没有按钮,没有错误发生

问题描述

蟒蛇版本 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()

按钮不起作用。请帮助检查导致此问题的原因。

标签: python-3.xkeyboardtelegram-bot

解决方案


添加logging,这样您就可以查看那里是否有任何错误或错误响应。

import logging

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

推荐阅读