How do I get my Telegram bot to write in monospace?

Question:

I am trying to write something in "monospace" with my telegram bot using the following Python function:

@bot.message_handler(commands=['test_monospace'])
def test_monospace(message):
    bot.reply_to(message, "```This message should be in monospace```")

Unfortunately, when I test the bot I get the message without the monospace formatting

The bot output

How can I get it to use monospace?

Asked By: Robb1

||

Answers:

You probably need to set the parse_mode to MarkdownV2:

bot.reply_to(message, "```This message should be in monospace```", parse_mode='MarkdownV2')

You could also use the telegram.Message.reply_markdown_v2 shortcut.


enter image description here

Answered By: 0stone0
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.