[英]How should I use parse_mode='HTML' in telegram python bot?
[英]How to use parse mode in telegram send message bot in Python
我對制作機器人很陌生,所以我有幾個問題想問:
我正在使用機器人發送消息
def send_message(chat_id, msg): url = f"https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={msg}" requests.get(url) send_message(chat_id,msg)
通過這個,我可以發送消息,我想通過使用 parse_mode 美化結果,但我不知道在 url 中的哪個位置使其工作。
我替代使用 Telethon。 我可以使用它通過用戶名和組邀請鏈接向個人和組發送消息,但是當我嘗試通過以下方式將其發送到頻道時:
client.send_message(entity='我的頻道名稱', message=message)
當我嘗試運行它時,它返回找不到與“測試通道”相對應的任何實體。
我也試試
destination_channel_username='test_ali3'
entity=client.get_entity(destination_channel_username)
client.send_message(entity=entity,message="Hi")
但它需要我的頻道access_hash,如何獲取它,或者有沒有其他方法可以向頻道發送消息。
非常感謝!
def send_message(chat_id, msg, parse_mode):
url = f"https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={msg}&parse_mode={parse_mode}"
requests.get(url)
TBH 我對 Telethon 不太熟悉,但該庫主要用於所謂的用戶機器人。 這意味着它使用了 Telegram 應用程序也使用的 API,因此,它通常比普通的機器人 api 更復雜。
To use the Bot API in Python, I can recommend the package python-telegram-bot
, see https://python-telegram-bot.org . 免責聲明:我目前是該 package 的維護者。 機器人 api 還有其他 python 包,參見例如https://core.telegram.org/bots/samples#python
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.