如何使用python-telegram-bot禁用Telegram消息链接预览?
解决python-telegram-bot禁用链接预览的问题
你的问题出在两个关键点:
- 错误地将
disable_web_page_preview设为None,这是参数默认值(对应启用预览状态),需要设为True才会触发禁用预览的效果 - 需确保参数被正确传递至
reply_html方法中
修改后的可用代码如下:
import logging from telegram.ext import Updater, CommandHandler, MessageHandler, Filters ... def link(update, context): update.message.reply_html( text=f"<a href='{link_to_send}'>This is an example</a>", disable_web_page_preview=True # 设置为True禁用网页预览 ) ...
另外你使用的是v20.0a4预览版本,该版本的reply_html方法确实支持disable_web_page_preview参数。如果参数仍不被识别,建议重新安装对应版本的库:
pip install python-telegram-bot==20.0a4
内容的提问来源于stack exchange,提问作者Jacopo Taramasso
相关产品推荐
相关产品推荐

