发送照片没有压缩,Telegrambot文件

发布于 2025-02-03 17:18:00 字数 298 浏览 4 评论 0原文

如何将照片发送到不压缩的情况下作为文件。当我使用当前方法实现它时,文件将作为文档发送而无需扩展。

bot = TeleBot("API")

@bot.message_handler(content_types=['text'])
def send(message):
    with open("5.jpg", "rb") as file:
        f = file.read()
    bot.send_document(message.chat.id, document=f)

bot.polling(True)

How do I send a photo to chat without compression, as a file. When I implement it with the current method, the file is sent as a document without an extension.

bot = TeleBot("API")

@bot.message_handler(content_types=['text'])
def send(message):
    with open("5.jpg", "rb") as file:
        f = file.read()
    bot.send_document(message.chat.id, document=f)

bot.polling(True)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贱人配狗天长地久 2025-02-10 17:18:00

当您

f = file.read()

document = f结合使用时,Telegram将接收文件的内容


要使用原始FILENAMEM发送文件,请从File 从open()

with open("/tmp/ccatt.jpeg", "rb") as file:
    bot.send_document(123456789, document=file)

“

When you do

f = file.read()

Combined with document=f, Telegram will receive the content of the file.


To send the file with the original filenamem, pass the file variable from open():

with open("/tmp/ccatt.jpeg", "rb") as file:
    bot.send_document(123456789, document=file)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文