【问题标题】:how to get image album data with pyTelegramBotAPI如何使用 pyTelegramBotAPI 获取相册数据
【发布时间】:2020-09-22 23:51:26
【问题描述】:

我制作了一个机器人来收集包括照片在内的一些信息,我需要保存照片。我只能保存相册中的 1 张照片,如何保存所有内容?

我将 python3 与 pyTelegramBotAPI 一起使用

@bot.message_handler(func=lambda message: True, commands=['test'])
def test(message):
   text_message = 'some question' 
   bot.send_message(message.chat.id,text_message) 
   bot.register_next_step_handler(message, test2) 

def test2(message):
   file_info = bot.get_file(message.photo[-1].file_id)
   print(file_info) 

我需要获取一组数据或下载所有照片。

【问题讨论】:

    标签: python telegram-bot py-telegram-bot-api


    【解决方案1】:

    您可以创建一个列表并在用户发送和图像时附加它。

    @bot.message_handler(commands=['sendimage'])
    def sendimage(m):
      cid = call.message.chat.id
      mid = call.message.message_id
      info = call.data
    
      msg= bot.send_message(cid, 'Send Image')
      bot.register_next_step_handler(msg, step_add_image)
    
    def step_add_image(m): 
      cid = m.chat.id
      photo_id= m.photo[-1].file_id
      addImg(cid,photo_id)
      bot.send_message(cid,'Next photo is added')
      bot.send_photo( cid, photo_id,reply_markup=aceptarPinKeyboard)
    
    def addImg(cid, photo_id):
        # Here you can add image id in JSON, DATABASE,...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多