Search code examples
telegramtelegram-botpython-telegram-bot

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?


Solution

  • 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