how save photo in telegram python bot?

2019-02-16 02:51发布

i want to write a telegram bot that save photos . this is my code , but its not working. and i don't know what is my problem?

def image_handler(bot, update):
    file = bot.getFile(update.message.photo.file_id)
    print ("file_id: " + str(update.message.photo.file_id))
    file.download('image.jpg')

updater.dispatcher.add_handler(MessageHandler(Filters.photo, image_handler))
updater.start_polling()
updater.idle()

pleas help me to solve my problem.

1条回答
Lonely孤独者°
2楼-- · 2019-02-16 03:28

update.message.photo is an array of photos sizes (PhotoSize objects).

Use file = bot.getFile(update.message.photo[-1].file_id). This will get the image with biggest size available.

查看更多
登录 后发表回答