Discord の /publish コマンドから Hugo 記事を GitHub にプッシュする Cloudflare Worker。
Discord /publish
↓ モーダル(ポップアップ)が開く
↓ タイトル / タグ / 本文 を入力して送信
Cloudflare Worker
↓ GitHub API でファイルを作成
sonohen.github.io/content/posts/YYYY/MM/DD/index.md
- https://discord.com/developers/applications でアプリを作成
- Bot タブ → Bot を追加 → Token をコピー
- General Information → Application ID と Public Key をコピー
- OAuth2 → URL Generator で
bot+applications.commandsスコープを選択してサーバーに招待
https://github.com/settings/tokens/new でトークンを作成(repo スコープが必要)
npm install
npx wrangler secret put DISCORD_PUBLIC_KEY
npx wrangler secret put DISCORD_BOT_TOKEN
npx wrangler secret put GITHUB_TOKENnpm run deployデプロイ後に表示される URL(例: https://discord-blog.<your-subdomain>.workers.dev)をコピーする。
Discord Developer Portal → アプリ → General Information →
Interactions Endpoint URL に Worker の URL を貼り付けて保存。
DISCORD_APPLICATION_ID=xxx DISCORD_BOT_TOKEN=yyy npm run registerDiscord で /publish と入力するとモーダルが開く。
| フィールド | 入力例 |
|---|---|
| タイトル | 今日の気づき |
| タグ | hugo blog または #hugo #blog |
| 本文 | 複数行テキスト |
投稿されるファイルパス: content/posts/YYYY/MM/DD/index.md
生成される記事形式:
+++
title = "今日の気づき"
date = "2026-04-25T10:00:00+09:00"
tags = ["hugo", "blog"]
draft = false
+++
本文がここに入る同じ日に複数投稿した場合は既存の index.md を上書きします。
(別記事を同日に公開したい場合はタイトルを含むサブディレクトリ構成への変更を検討してください)
discord-blog/
├── package.json
├── wrangler.toml # Cloudflare Worker 設定
├── register-commands.js # スラッシュコマンド登録スクリプト
└── src/
├── index.js # エントリーポイント・署名検証
├── discord.js # Interaction ハンドラー
└── github.js # GitHub API でファイル作成