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}")