How do I download a file or photo that was sent to my Telegram bot?

前端 未结 6 1664
太阳男子
太阳男子 2020-12-12 18:11

I am using the telegram bot API but I cant see anyway to download a filé that was sent to my bot. I get a hash of the file but dont know what to do with it. Is there any way

6条回答
  •  情话喂你
    2020-12-12 18:31

    If you are using pyTelegramBotAPI you can download your photo using this code:

    raw = message.photo[2].file_id
    path = raw+".jpg"
    file_info = bot.get_file(raw)
    downloaded_file = bot.download_file(file_info.file_path)
    with open(path,'wb') as new_file:
        new_file.write(downloaded_file)
    

提交回复
热议问题