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

如何限制用户转发或保存Telegram机器人发送的内容?

如何让Telegram机器人发送的图片/视频无法被保存
  • 核心逻辑:Telegram Bot API提供了protect_content参数,将其设为True即可限制用户保存、转发Bot发送的图片或视频(官方客户端层面生效,部分第三方工具可能存在绕过,但属于非官方操作)。

  • 主流Bot框架实现示例:

    • python-telegram-bot(v13及以上版本):
      from telegram.ext import Updater, CommandHandler
      
      def send_protected_media(update, context):
          # 发送不可保存的图片
          update.message.reply_photo(
              photo="你的图片URL或本地路径",
              protect_content=True
          )
          # 发送不可保存的视频
          update.message.reply_video(
              video="你的视频URL或本地路径",
              protect_content=True
          )
      
      if __name__ == "__main__":
          updater = Updater("你的Bot令牌")
          dp = updater.dispatcher
          dp.add_handler(CommandHandler("send", send_protected_media))
          updater.start_polling()
          updater.idle()
      
    • Pyrogram:
      from pyrogram import Client
      
      app = Client("my_bot", bot_token="你的Bot令牌")
      
      @app.on_message()
      async def handle_msg(client, message):
          if message.text == "/send":
              # 发送不可保存的图片
              await client.send_photo(
                  chat_id=message.chat.id,
                  photo="你的图片URL或本地路径",
                  protect_content=True
              )
              # 发送不可保存的视频
              await client.send_video(
                  chat_id=message.chat.id,
                  video="你的视频URL或本地路径",
                  protect_content=True
              )
      
      app.run()
      
  • 关键注意点:

    • 该参数仅对Bot主动发送的媒体生效,无法限制用户发送的内容。
    • 不同编程语言的Bot框架,只需在对应发送媒体的方法中添加protect_content=True(或对应语言的布尔值写法)即可,比如Node.js的Telegraf框架中用protect_content: true。
    • 官方客户端会严格限制保存和转发操作,但部分第三方截图工具可能绕过限制,这属于平台外的特殊情况。

内容的提问来源于stack exchange,提问作者Gordon Freeman

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 07:52:07