Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python telegrame.py:按钮创建_Python_Telegram_Python Telegram Bot - Fatal编程技术网

Python telegrame.py:按钮创建

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

我目前正在用Python制作一份电报。我想知道如何制作这样的功能按钮

我想让
/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
是否可以使用代码将其可视化?我理解的比解释容易。这就是我链接示例的原因;)但我仍然不明白如何以不同的方式处理回调查询