Skip to content

Instantly share code, notes, and snippets.

@MtkN1
Last active October 8, 2024 03:11
Show Gist options
  • Save MtkN1/95ff4c43048b5e4ebb3a6d7450ae13d2 to your computer and use it in GitHub Desktop.
Save MtkN1/95ff4c43048b5e4ebb3a6d7450ae13d2 to your computer and use it in GitHub Desktop.
Discord notify sample
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)
@MtkN1
Copy link
Author

MtkN1 commented Oct 8, 2024

通知画面:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment