无法通过 Telegram Bot 发送图片

Not able to send Images via Telegram Bot

当我发出命令时,它就是没有反应。我的所有其他命令都运行良好。我正在使用 pytelegrambotapi.

我的代码-

import telebot
from PIL import Image
import requests
from io import BytesIO
    
#This is my image link
IMAGE_LINK = "https://pixabay.com/images/id-1127657/"
    
@bot.message_handler(commands=['image'])
def image(message):
    response = requests.get(IMAGE_LINK)
    img = Image.open(BytesIO(response.content))
    #send the photo
    bot.send_photo(message.chat.id, img)

您的图片 url 不正确,它会转到包含其他元素以及图片本身的页面。 您图片的正确 url 是: https://cdn.pixabay.com/photo/2016/01/08/11/49/text-1127657_960_720.jpg

您也可以将此 link 直接传递给 send_photo,这样 Telegram 本身就会从 url:

下载并发送照片
IMAGE_LINK = "https://cdn.pixabay.com/photo/2016/01/08/11/49/text-1127657_960_720.jpg"


@bot.message_handler(commands=['image'])
def image(message):
    bot.send_photo(message.chat.id, IMAGE_LINK)