Skip to content

sonohen/pdsc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

discord-blog

Discord の /publish コマンドから Hugo 記事を GitHub にプッシュする Cloudflare Worker。

仕組み

Discord /publish
   ↓ モーダル(ポップアップ)が開く
   ↓ タイトル / タグ / 本文 を入力して送信
Cloudflare Worker
   ↓ GitHub API でファイルを作成
sonohen.github.io/content/posts/YYYY/MM/DD/index.md

セットアップ

1. Discord Application を作成

  1. https://discord.com/developers/applications でアプリを作成
  2. Bot タブ → Bot を追加 → Token をコピー
  3. General Information → Application ID と Public Key をコピー
  4. OAuth2 → URL Generatorbot + applications.commands スコープを選択してサーバーに招待

2. GitHub Token を作成

https://github.com/settings/tokens/new でトークンを作成(repo スコープが必要)

3. Wrangler でシークレットをセット

npm install
npx wrangler secret put DISCORD_PUBLIC_KEY
npx wrangler secret put DISCORD_BOT_TOKEN
npx wrangler secret put GITHUB_TOKEN

4. Worker をデプロイ

npm run deploy

デプロイ後に表示される URL(例: https://discord-blog.<your-subdomain>.workers.dev)をコピーする。

5. Discord に Interactions Endpoint URL を登録

Discord Developer Portal → アプリ → General Information
Interactions Endpoint URL に Worker の URL を貼り付けて保存。

6. スラッシュコマンドを登録

DISCORD_APPLICATION_ID=xxx DISCORD_BOT_TOKEN=yyy npm run register

使い方

Discord で /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 でファイル作成

About

Publish from Discord Slash Command

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors