【问题标题】:How to send bold text using Telegram Python bot如何使用 Telegram Python bot 发送粗体文本
【发布时间】:2018-08-25 21:46:57
【问题描述】:

我正在用 Python 编写一个电报机器人。我想发送带有粗体字母的消息。我试图在*** 中都包含消息,但它并没有解决问题。

是否有标记或 HTML 格式的功能或方法?

【问题讨论】:

    标签: python bots telegram


    【解决方案1】:

    这有点晚了。但我希望对其他人有所帮助:

    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' )  
    

    【讨论】:

      【解决方案2】:

      你应该使用:

      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-

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-16
        • 2015-11-26
        • 2020-10-09
        • 2019-08-23
        • 2018-04-20
        • 1970-01-01
        相关资源
        最近更新 更多