如何创建带有标记但没有电报文本的消息?

How to create a message with markup but without a text in telegram?

我有这样的回复键盘:

keyboard = [
        [
            InlineKeyboardButton("Play with a bot", callback_data=str(ONE)),
            InlineKeyboardButton("Results", callback_data=str(TWO)),
        ]
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)

    update.message.reply_text(None, reply_markup=reply_markup)

给我这样的结果:

如何去掉第一个“空”字符串?

您将 None 作为标题传递,结果是 null,您应该传递一条消息,因为它是 send_messagereply_text 方法所必需的:

text (str) – Text of the message to be sent. Max 4096 characters after entities parsing. Also found as telegram.constants.MAX_MESSAGE_LENGTH.

因此,由于您需要添加一些文本,因此将其作为额外参数传递给函数:

keyboard = [
    [
        InlineKeyboardButton("Play with a bot", callback_data='a'),
        InlineKeyboardButton("Results", callback_data='b'),
    ]
]
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text('How can I help?', reply_markup=reply_markup)


如我的评论所述,发送单独的消息也需要一些文本

您不能发送没有文本或 Telegram 支持的任何类型的媒体(照片、视频、音频等)的内联键盘。相反,如果您只想更新内联键盘而不更改消息内容,请使用 editMessageReplyMarkup 方法。这将更新内联键盘,同时保留原始消息。