Can you list members of a guild you're not a part of with a Discord bot? I'm trying to grab guild members but it looks like:
Number 2 is the one I'm uncertain of, some documentation seems to indicate that you can just add the guild's ID (which I grabbed via developer view) but the guild is returning "undefined" so I'm wondering if the problem is that number 2 is true but just not explicitly mentioned in any docs i could find.
I also thought of a workaround being to use my personal account that's already in the server's client id but I'm not sure I can set a client instance to my personal user ID.
If so how would I do that? I've already checked that my bot has privileged gateway intents enabled to grab members, but my client.guilds.cache.get("GUILD_ID"); is returning "undefined" (note that in my actual code this is the real guild ID).
Below is the full code, including configuration since I haven't seen anyone list that and I'm not even sure how the code is supposed to know what my clientID is meant to be
//Gets Discord API Wrapper
const discord = require("discord.js");
const fs = require('fs')
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
//This doesn't seem to actually do anything :/
client.on("ready", () => {
console.log("I am ready!");
});
//GUILD_ID is my actual guild ID in live code
const list = client.guilds.cache.get("GUILD_ID");
console.log(list);
// Fetch and get the list named 'members'
list.members.each(member => {
console.log(member.user.username)
let content = member.displayName + "_" + member.user.id + "_" + member.user.nickname + "_" + member.user.username
console.log(content)
// Do whatever you want with the current member
fs.writeFile('/memberinfo.txt', content, { flag: 'a+' }, err => {
if (err) {
console.error(err)
return
}
})
});
//official docs include this after other code, but why after? TOKEN_VALUE is actual token in live code
client.login("TOKEN_VALUE");
I haven't even gotten past list.members.each(member => { so the code below is probably incorrect, but I just can't figure out why console.log(list); spits out "undefined" which is causing the following error:
TypeError: Cannot read properties of undefined (reading 'members')
Do I need to set clientId? How would I do that? What's the point of the token the bot generated if it's being set after the call is supposed to be made?