Alright, so, I made a simple button system and I added this bit of code:
bot.on('interactionCreate', async interaction => {
interaction.guild.members.cache.forEach(m => {
console.log(m.user.username)
});
});
And whenever I check my console, it only prints two usernames, me and my bot’s name. Why isn’t it printing every single user inside of the guild’s names?
>Solution :
cache will return only the cached members in the guild, hence it’s name. You’ll want to fetch the members first.
bot.on('interactionCreate', async interaction => {
const allMembers = await interaction.guild.members.fetch();
allMembers.forEach(m => {
console.log(m.user.username);
});
});
Ensure you have the Guild Member’s intent enabled