Telegram.py : 创建按钮

Telegram.py : Buttons creating

我目前正在使用 Python 制作 Telegram。我想知道如何制作这样的功能按钮

https://i.stack.imgur.com/e3eMb.png

我想使 /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()

您正在寻找的是所谓的内联按钮。查看 official docs and this python-telegram-bot example.


免责声明:我目前是 python-telegram-bot.

的维护者