python-3.x - 电报自定义键盘按钮不起作用。执行后,电报中没有按钮,没有错误发生
问题描述
蟒蛇版本 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()
按钮不起作用。请帮助检查导致此问题的原因。
解决方案
添加logging,这样您就可以查看那里是否有任何错误或错误响应。
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
推荐阅读
- oracle - 转换为 Unicode 后计算数据库大小
- node.js - Heroku 部署混乱:Vue.js 前端与 Flask 后端
- python-3.x - 当我使用 --libdir=/usr/lib64 构建 Python 3.6.7 时,我无法导入 ssl
- openstreetmap - Ruby Geocoder 和/或 OpenStreetMap 存在很大的误差
- reactjs - Redux 一直显示未定义状态
- python - 如何以简单的方式区分输入中的数字?
- javascript - chrome 中的网络推送通知
- haskell - 使用 Nix 构建 Haskell 包时如何流式传输测试输出?
- powershell - 用于从命令行输出中捕获部分数据的 powershell 脚本
- esp8266 - NodeMCU SPI 总线不响应命令