【发布时间】:2018-08-25 21:46:57
【问题描述】:
我正在用 Python 编写一个电报机器人。我想发送带有粗体字母的消息。我试图在* 和** 中都包含消息,但它并没有解决问题。
是否有标记或 HTML 格式的功能或方法?
【问题讨论】:
我正在用 Python 编写一个电报机器人。我想发送带有粗体字母的消息。我试图在* 和** 中都包含消息,但它并没有解决问题。
是否有标记或 HTML 格式的功能或方法?
【问题讨论】:
这有点晚了。但我希望对其他人有所帮助:
import telepot
token = 'xxxxxxxxxxxxxxx' # Your telegram token .
receiver_id = yyyyyyyy # Bot id, you can get this by using the next link :
https://api.telegram.org/bot<TOKEN>/getUpdates. Note that you should
replace <TOKEN> with your token.
bot = telepot.Bot(token)
message = "*YOUR MESSAGE YOU WENT TO SEND.*" #Any characters between ** will be
send in bold format.
bot.sendMessage(receiver_id, message , parse_mode= 'Markdown' )
【讨论】:
你应该使用:
bot.send_message(chat_id=chat_id, text="*bold* Example message",
parse_mode=telegram.ParseMode.MARKDOWN)
或者:
bot.send_message(chat_id=chat_id, text='<b>Example message</b>',
parse_mode=telegram.ParseMode.HTML)
【讨论】: