python - Save an image or several files what my telegram bot gets, to a specific directory
问题描述
@self.__bot.message_handler(content_types=['photo'])
def on_photo(message):
file_id = message.photo[-1].file_id
file_info = self.__bot.get_file(file_id)
I created a bot in the telegram and one of the commands is to send a picture to create a post from it. I want the image you send to it to be saved in the folder of my choice ... How do you do that? I use telebot in python I would love to help
解决方案
@self.__bot.message_handler(content_types=['photo'])
def on_photo(message):
file_id = message.photo[-1].file_id
file_info = self.__bot.get_file(file_id)
file = requests.get('https://api.telegram.org/file/bot{0}/{1}'.format(API_TOKEN, file_info.file_path))
with open('photo.jpg','wb') as f:
f.write(file.content)
推荐阅读
- android - 如何在android中禁用listView的回收
- python - time.sleep 与 threading.Lock 的交互
- javascript - 打字稿枚举键入错误(“字符串”类型的参数不可分配给类型的参数)
- sql - 查询以执行表中列的值
- android - 如何让此代码在 onMapReady 中自动执行
- c - 如何使用 Enter 键退出 C 程序
- javascript - React,Formik,使用字段数组的可重复表单字段
- java - 我正在寻找代码以成功将从我的输入文件中读取的信息存储到 Java 中的 ArrayList 中
- javascript - 使用 javascript 自动滑动轮播而不是内置导航
- javascript - 如何在 java 应用程序中使用 reactjs 库?