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.
2
Answers
You can use the
formatting
package from Telebot to format your text like this:See the pytba docs for all formatting styles.
The default
parse_mode
can be passed to theTeleBot
class like so:If you want to set it for a single message,
send_message
also exceptsparse_mode
: