You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 18:50:26