2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PythonでDiscordに画像を送る

Posted at

Pythonで監視カメラを作ったので撮影した画像をDiscordに送りたい。

意外と探したけどなかったので記載

import reqest

def send_discord(webhook_url,msg, image_path="" ):
    print("Discodeに送信中")
    try:
        with open(image_path, 'rb') as image_file:
            payload = {
                "content": msg,
                "file": image_file
            }
            response = requests.post(webhook_url, files=payload)
            response.raise_for_status()
            print("Image sent successfully")
    except FileNotFoundError:
        print("File not found.")
    except requests.exceptions.RequestException as err:
        print(f"Error sending image via : {err}")

いけた!
1回Fileだけしかでなかったのだがバイナリデータで送ってるからとかなんとからしい
image.png

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?