我想写一个保存照片的电报机器人。这是我的代码,但它不起作用。我不知道我的问题是什么?
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()
请帮我解决我的问题。
原文由 Ali Akhtari 发布,翻译遵循 CC BY-SA 4.0 许可协议
update.message.photo
是一组照片尺寸(PhotoSize 对象)。使用
file = bot.getFile(update.message.photo[-1].file_id)
。这将获得可用的最大尺寸的图像。