我正在尝试执行一条命令,以列出每个带有特定类型标志的用户,例如“ HYPESQUAD_BALANCE”
const users = message.mentions.members.first() || message.guild.members.cache.get(args[0]) || message.member;
const flags = await users.user.fetchFlags()
const userFlags = flags.toArray()
const status = userFlags.includes('HYPESQUAD_BALANCE')
console.log(status)
命令的那部分工作正常,但是那不是我想要的,我想吸引每个用户
所以我已经尝试过
const members = client.users.cache.array()
const array = [];
for (const user of members) array.push(user.flags ? user.flags : await user.fetchFlags());
console.log(array)
没有错误,但如果有人可以帮助我,则返回任何内容
答案 0 :(得分:0)
以下代码对我有用:
const users = client.users.cache.array();
const validUsers = []:
for(let user of users){
const flags = user.flags || await user.fetchFlags();
const hasFlag = flags.toArray().includes("HYPESQUAD_BALANCE");
if(hasFlag) validUsers.push(user);
}
console.log(validUsers); // all the users who have the badge