Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DiscordとCloudflare

sugar-cat
February 14, 2025
140

 DiscordとCloudflare

sugar-cat

February 14, 2025
Tweet

Transcript

  1. 3 Bot or Activity(ボイスチャット上で動くWebアプリケーション) Discordの開発でできること(2025年2月15日現在) Overview of Activities https://discord.com/developers/docs/activities/overview Overview

    of Interactions https://discord.com/developers/docs/interactions/overview ・Interaction(/ command) ・Events ・Gateway(WebSocket)/Webhook ・Embedded App ・iframeを通したメッセージング ・Unity(WebGLビルド)もいける(はず)
  2. 4 Bot or Activity(ボイスチャット上で動くWebアプリケーション) Discordの開発でできること(2025年15日現在) Overview of Activities https://discord.com/developers/docs/activities/overview Overview

    of Interactions https://discord.com/developers/docs/interactions/overview ・Interaction(/ command) ・Events ・Gateway(WebSocket)/Webhook ・Embedded App ・iframeを通したメッセージング ・Unity(WebGLビルド)もいける(はず) Overview of Interactions https://discord.com/developers/docs/interactions/overview ・Interaction(/ command) ・Events ・Gateway(WebSocket)/Webhook
  3. 5 Bot or Activity(ボイスチャット上で動くWebアプリケーション) Discordの開発でできること(2025年15日現在) Overview of Activities https://discord.com/developers/docs/activities/overview Overview

    of Interactions https://discord.com/developers/docs/interactions/overview ・Interaction(/ command) ・Events ・Gateway(WebSocket)/Webhook ・Embedded App ・iframeを通したメッセージング ・Unity(WebGLビルド)もいける(はず) Overview of Interactions https://discord.com/developers/docs/interactions/overview ・Interaction(/ command) ・Events ・Gateway(WebSocket)/Webhook /hogeでユーザーからのインタラクションを受けられる
  4. 7 • InteractionはInteractions Endpointを介してDiscordからのリクエ ストを受けられれば良いのでサーバレスの実行環境でOK • 公式からSDKが提供されているのでそれを使えば基本的には全部実装 できる(Interaction以外も) Cloudflare ×

    Discord Interactionの開発方法 https://github.com/discordjs 残念ながらCloudflare上ではdiscord.jsは動かない ※Node.js実行環境への依存・workerdでWeakRefが使えない等 ので、一般的にはInteractionだけ切り出したdiscord-interactions-jsが 使われる
  5. 8 ただDiscordの他APIの併用やWebFrameWorkへの統合を考えると もう少しリッチなライブラリが欲しくなる...(と思う) discord.jsを使わずに楽する DiscordHono ・Honoにinspireされたライブラリ ・Cloudflare Workersで動く ・Honoへmountが可能 ・Discord

    API操作用のRESTClient  の提供あり Discordeno ・Node.js/Deno/Bunで動く(使って いる限りはworkerdも) ・rest/gateway/botでパッケージ化 されている ・シンプルで拡張性に重きが置かれ ている(キャッシュを使用しない等) https://github.com/luisfun/discord-hono https://github.com/discordeno/discordeno Sapphire ・大規模向け(?) ・discord.jsに一部依存している ・pluginが超豊富(i18n/cli etc…) ・基本的Discord APIの操作は Wrapperが提供されている https://github.com/sapphiredev/framework
  6. 10 全体構成 サーバーサイドをCloudflareStackに (鋭意リプレイス中) ・外部向けのエンドポイントはAPI Gateway Workersに集約 ・内部のビジネスロジックはInternal Workerへ集約(Service Bindings)

    ・Read/Write用のWorkersを分けDB の書き込みスケールのためバッファリン グ ・Cronからの呼び出しはWorkflowsを 使用しステップに分け効率的に処理 ・BaselimeによるTracing強化 Discord Channelへの一斉配信とInteraction ユースケース (個人)