1

I can't figure out how to format the text in the Telegram bot.

The code is the following:

import telebot

bot = telebot.TeleBot(TOKEN)

@bot.message_handler(commands=['start', 'help'])
def help(message: telebot.types.Message):
    text = "<b> Test message </b>"
    bot.reply_to(message, text)

Where should I put parse_mode='HTML'?

I tried:

1.bot.reply_to(message, text, parse_mode='HTML')

2.bot = telebot.TeleBot(TOKEN, parse_mode='HTML')

I want the bot to format the message: make individual words or sentences bold, italic or underlined.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

2 Answers2

1

The default parse_mode can be passed to the TeleBot class like so:

bot = telebot.TeleBot("TOKEN", parse_mode='MARKDOWN')

If you want to set it for a single message, send_message also excepts parse_mode:

bot.send_message(message.chat.id, '<b>some text</b>', parse_mode='HTML')
0stone0
  • 34,288
  • 4
  • 39
  • 64
0

You can use the formatting package from Telebot to format your text like this:

from telebot import formatting

formatting.hbold("hello")
formatting.hitalic("world")
formatting.hunderline("!")

See the pytba docs for all formatting styles.

kaiffeetasse
  • 481
  • 1
  • 8
  • 18