Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bot only finding me and bot in guild members? (Discord.js V13)

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading