Last active
October 8, 2024 03:11
-
-
Save MtkN1/95ff4c43048b5e4ebb3a6d7450ae13d2 to your computer and use it in GitHub Desktop.
Discord notify sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import requests | |
# Discord の チャンネルの編集 -> 連携サービス -> ウェブフックを作成 -> ウェブフック URL をコピー で取得できる | |
WEBHOOK_URL = os.getenv("WEBHOOK_URL", "https://discordapp.com/api/webhooks/...") | |
# bitFlyer REST API で ticker を取得する (サンプル) | |
r = requests.get("https://api.bitflyer.com/v1/ticker") | |
ticker = json.dumps(r.json(), indent=4) | |
# Discord Webhook API で通知を送信する | |
r = requests.post( | |
WEBHOOK_URL, | |
json={ | |
"content": f"@everyone bitFlyer Ticker\n```json\n{ticker}\n```", | |
}, | |
) | |
# エラー処理 | |
if not r.ok: | |
print(r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
通知画面: