Telegram Bot API支持通过HTML标记语言格式化文本消息。要在消息中换行,请在HTML中使用“
”标记。以下是一个例子:

import telegram

# 创建bot对象
bot = telegram.Bot(token='YOUR_TOKEN_HERE')

# 发送HTML格式的消息
bot.send_message(chat_id='CHAT_ID_HERE', text='Hello <b>World</b><br>This is a new line!', parse_mode=telegram.ParseMode.HTML)

在上面的例子中,我们使用了telegram.ParseMode.HTML参数来告诉Telegram Bot API解析HTML标记语言。<b>标记将文本加粗,<br>标记将文本换行。请注意,在文本消息中使用HTML标记语言时,必须将parse_mode参数设置为HTML

telegram bot 发送html消息 br换行 不能解析

原文地址: https://www.cveoy.top/t/topic/hnBt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录