[英]How can I bold text in telepot Telegram bot?
我已经试过了
elif command == 'bold':
telegram_bot.sendMessage (chat_id, str("*bold*"), reply_markup=markup)
但这是回复*bold*
而不是粗体
您需要提供一个parse_mode
参数(parse_mode =“ Markdown”)。
否则,您将看不到任何降价样式。
sendMessage(chat_id, "*this text is bold*", parse_mode= 'Markdown')
看到
https://telepot.readthedocs.io/en/latest/reference.html#telepot.Bot.sendMessage
从-> 我如何在python telegram bot中写粗体
您应该使用:
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)
有关更多信息, 请访问: https : //github.com/python-telegram-bot/python-telegram-bot/wiki/Code-snippets#message-formatting-bold-italic-code-
我对Markdown parse_mode有同样的问题。 我自己编写了send_message,没有使用Telepot的sendMessage方法。 在这种情况下,更容易理解如何处理此问题:
url = 'https://api.telegram.org/bot<token>'
def send_message(chat_id, text='empty line', parse_mode = 'Markdown'):
URL = url + 'sendMessage'
answer = {'chat_id': chat_id, 'text': text, 'parse_mode': 'Markdown'}
r = requests.post(URL, json=answer)
return r.json()
if (text == '/bold'):
send_message(chat_id, 'Here comes the'+'*'+'bold'+'*'+'text!')
另一方面,您可以使用curl发送粗体文本:
if (text == '/bold'):
URL = url + 'sendMessage?chat_id='+chat_id+'&text=*Here comes the bold text*&parse_mode=Markdown'
answer = {'chat_id': chat_id, 'text': text}
r = requests.post(URL, json=answer)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.