how save photo in telegram python bot?

女生的网名这么多〃 提交于 2020-01-10 20:11:10

问题


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:


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.



来源:https://stackoverflow.com/questions/50388435/how-save-photo-in-telegram-python-bot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!