generated at
サーバーからあるユーザー名で始まるメンバーを取得する
GuildMemberManager#fetchのqueryに適当な文字列を入れるとその文字列で始まるユーザー名のメンバーを取得することができる。
ただしqueryを空のままで呼び出すとServer Members Intentが無い場合エラーになる。
REST APIではなくGateway APIを使って取得している

> string that username starts with, or an empty string to return all members

js
const discord = require("discord.js"); const username = "username"; const client = new discord.Client({ intents: discord.Intents.FLAGS.GUILDS, }); client.on("ready", async ()=>{ const guild = client.guilds.cache.first(); const members = await guild.members.fetch({ query: username, }); console.log(members); }); client.login("token");