亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Telehton newMessage 事件中識別和下載圖像?

如何在 Telehton newMessage 事件中識別和下載圖像?

一只斗牛犬 2022-06-07 18:01:17
我編寫了一個簡單的 python 腳本來使用 Telethon 事件處理程序將用戶看到的所有消息保存到文件中:@CLIENT.on(events.NewMessage)async def my_event_handler(event):    sender = await event.get_sender()    chat_id = event.chat_id    out ='\n\n' +  sender.username + ': ' + event.text + ' [' + str(chat_id) + ']'    name = hashlib.sha1(out.encode('utf-8')).hexdigest()    outdir = ECHODIR + '/' + str(chat_id)    f_h = open(outdir + '/' + name, 'a')    f_h.write(out)    f_h.close()CLIENT.start()CLIENT.run_until_disconnected()如何檢測收到圖像并從事件中下載圖像?ps 刪除了不必要的代碼,例如檢查目錄是否存在
查看完整描述

1 回答

?
MM們

TA貢獻1886條經驗 獲得超2個贊

根據 的對象參考摘要Message,該message.photo屬性將是“此消息中的照片媒體,如果有的話。”。

這意味著,要檢測代碼中的圖像(或照片),您可以執行以下操作:

if event.photo:
    ...

這些Message方法還包含一個message.download_media()這樣的:

saved_path = await event.download_media(optional_path)


查看完整回答
反對 回復 2022-06-07
  • 1 回答
  • 0 關注
  • 163 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號