【雑記】Discord APIでギルドタグの装着状況(?)を調べる方法

Botを作るときに必要になったので調べてみました。

検証環境:
メイン鯖機(i5-1135G7)
※執筆時点での情報となります。APIの仕様が変更された場合、このページの内容は使用できない可能性があります。

GET https://discord.com/api/v10/users/{:id}
Authorization: Bot ${DISCORD_TOKEN}

レスポンス例(整形済み):

yu-yu0202@ubuntu-main:~$ curl -H "Authorization: Bot ${DISCORD_TOKEN}" https://discord.com/api/v10/users/1264130543008612426
{
  "id": "1264130543008612426",
  "username": ".yu_yu0202.",
  "avatar": null,
  "discriminator": "0",
  "public_flags": 128,
  "flags": 128,
  "banner": null,
  "accent_color": null,
  "global_name": "ゆーゆー' or '1'='1' -- .",
  "avatar_decoration_data": null,
  "collectibles": null,
  "banner_color": null,
  "clan": {
    "identity_guild_id": "1297608893823979660",
    "identity_enabled": true,
    "tag": "WEBM",
    "badge": "98a36e3622f2fc3d660a4c4e176fd695"
  },
  "primary_guild": {
    "identity_guild_id": "1297608893823979660",
    "identity_enabled": true,
    "tag": "WEBM",
    "badge": "98a36e3622f2fc3d660a4c4e176fd695"
  }
}
タグ未装着の場合
yu-yu0202@ubuntu-main:~$ curl -H "Authorization: Bot ${DISCORD_TOKEN}" https://discord.com/api/v10/users/1354619221954527232
{
  "id": "1354619221954527232",
  "username": "yu_yu0202",
  "avatar": null,
  "discriminator": "0",
  "public_flags": 0,
  "flags": 0,
  "banner": null,
  "accent_color": null,
  "global_name": "ゆーゆー@sub",
  "avatar_decoration_data": null,
  "collectibles": null,
  "banner_color": null,
  "clan": {
    "identity_guild_id": null,
    "identity_enabled": false,
    "tag": null,
    "badge": null
  },
  "primary_guild": {
    "identity_guild_id": null,
    "identity_enabled": false,
    "tag": null,
    "badge": null
  }
}

これを使って「特定のギルドタグをつけていた場合」などのif分岐や、ユーザーがつけているタグの取得もできます。(D.jsは実装がまだなはずなので大人しくfetchしましょう)

※users APIは仕様によりBotとかかわりのある(同サーバー参加etc)ユーザーでないと取得できません。

コメント

タイトルとURLをコピーしました