1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Discordに自動的に参加させるスコープについて調べてみた

Last updated at Posted at 2025-12-02

この記事は デジタル創作サークル UniProject Advent Calendar 2025 3 日目の記事です。

背景

当サークルでは現在、内製のメンバー管理・認証基盤アプリケーションの UniQUE なるものを制作しています。

UniQUE を作る上で以下の機能が必要になります。

  • OIDC/OAuth2.0
  • メンバー管理
    • メンバー登録申請の管理

このメンバー登録申請は従来まで Google Form で管理しており、申請してきたのに Discord 鯖にいないので承認できないという人がそこそこいました。
そこで、UniQUE では Discord サーバーに自動的に追加したいなと思い、API を漁ってみました。

guilds.join スコープ

OAuth のリンクジェネレーターをみてみると、guilds.join なるスコープがあることがわかります。

スコープ一覧の切り抜き

これを使えばなんとなく参加させられるような気がします。

Add Guild Member

Discord のドキュメントに、こんな記述があります。

Adds a user to the guild, provided you have a valid oauth2 access token for the user with the guilds.join scope. Returns a 201 Created with the guild member as the body, or 204 No Content if the user is already a member of the guild. Fires a Guild Member Add Gateway event.

つまり、OAuth2.0 のアクセストークンがあれば、そのアプリの Bot がいるサーバーに参加させることができるようです。

curl でやってみる

OAuth のトークンの取得は割愛します。

curl -H "Authorization: Bot <Botのトークン>" -XPUT https://discord.com/api/v10/guilds/{guild.id}/members/{user.id} -d `{
  "access_token": "<OAuth2.0 トークン>"
}`

これで、参加させることができました!

Discordのシステムメッセージ

最後に

当サークルでは、この Discord 連携機能も用いて OIDC を活用したサークル内認証基盤を構築中です。
もし興味がありましたら、下記リンクからご参加いただけますと幸いです!

⭐︎ 公式 HP ↓

⭐︎ 公式 Discord サーバー ↓

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?