Kenenbek Arzymatov
Kenenbek Arzymatov

Reputation: 9119

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

I have such replying keyboard:

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)

It gives me such a result:

enter image description here

How can I get rid of the first "null" string?

Upvotes: 3

Views: 6239

Answers (2)

0stone0
0stone0

Reputation: 43983

You're passing None as the Title, resulting in null, you should pass a message as it's required for the send_message and reply_text method:

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

So, since you're required to add some text, pass it as the a extra argument to the function:

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)

enter image description here


As described in my comment, sending a separate message also requires some text

Upvotes: 3

GioIacca9
GioIacca9

Reputation: 436

You cannot send an inline keyboard without text or any type of media supported by Telegram (photos, videos, audios etc). If instead you only want to update the inline keyboard without changing the message content, use the editMessageReplyMarkup method. This will update the inline keyboard leaving the original message intact.

Upvotes: 1

Related Questions