我正尝试使用以下代码将完整的成员列表(包括脱机成员)导出到.csv。但是,使用“ message.guild.members”,我只捕获了缓存的Member。我如何更改它以使所有人(包括非缓存成员)都包括在内?
const auditUsers = (message) => {
console.log(message)
let allMembers = []
for (let m of message.guild.members.values()){
if (m.user.bot == true) continue
let member = {
Name: m.user.username,
Tag: m.user.tag,
UserID: `<@${m.user.id}>`,
JoinDate: m.joinedAt.toDateString()
}
let memberRoles = []
for (let r of m.roles.values()){
if (r.name != "@everyone") memberRoles.push(r.name)
}
member.Roles = memberRoles.join(', ')
allMembers.push(member)
}
const json2csvParser = new Json2csvParser()
const csv = json2csvParser.parse(allMembers)
fs.writeFileSync(`./${message.guild.name}_audit.csv`, csv, {flag: 'w'}, function(err){
if (err) consoleLog('Error saving CSV file:' + err.message, "ERR")
})
}