Python telegrame.py:按钮创建
我目前正在用Python制作一份电报。我想知道如何制作这样的功能按钮 我想让Python telegrame.py:按钮创建,python,telegram,python-telegram-bot,Python,Telegram,Python Telegram Bot,我目前正在用Python制作一份电报。我想知道如何制作这样的功能按钮 我想让/command命令有一个按钮,上面写着“这是一个按钮”。我怎么做?以下是我的帮助代码: # Modules needed import time from time import sleep import random import logging from telegram.ext import Updater, CommandHandler, MessageHandler, Filters # Enable
/command
命令有一个按钮,上面写着“这是一个按钮”。我怎么做?以下是我的帮助代码:
# Modules needed
import time
from time import sleep
import random
import logging
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
# /command
def command(update, context):
update.message.reply_text("Reply here")
def error(update, context):
"""Log Errors caused by Updates."""
logger.warning('Update "%s" caused error "%s"', update, context.error)
def main():
"""Start the bot."""
# Create the Updater and pass it your bot's token.
updater = Updater("[TOKEN]", use_context=True)
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.add_handler(CommandHandler("command", command))
# log all errors
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
你要找的是所谓的内联按钮。查看和此
python电报bot
免责声明:我目前是
python电报bot
的维护者,我测试并修改了它。我现在有另一个问题。Bot仅表示您从所有三个按钮中选择:[option]。我想让bot在每个按钮上都有不同的响应。您可以通过根据回调数据以不同方式处理回调查询
。直接在按钮回调中检查callback\u数据
,或者使用CallbackQueryHandler
的模式
参数。另请参见更详细的示例,包括ConversationHandler
是否可以使用代码将其可视化?我理解的比解释容易。这就是我链接示例的原因;)但我仍然不明白如何以不同的方式处理回调查询