Search code examples
javascriptdiscorddiscord.js

Cannot read properties of undefined (reading 'fetch') on guild.members.fetch()


I am working on setting a script that will cycle thorough all the members in a guild without using the cache system. I am getting an issue where when I use guild.members.fetch() it treats guild.members as undefined. I know it isn't because I am currently logging guild.members and it is giving me a GuildMemberManager object. I don't understand when once I use fetch() on it, it is suddenly being viewed as undefined. Here is a screenshot of the entire error message

function addMissingJsons(message, bot) {
    bot.guilds.fetch("id").then(guild => {
        console.log(guild.members);
        guild.memebers.fetch().then(members => {
            console.log(members);
        });
    });
}

Solution

  • As @mswgen said, you have a typo. It should be guild.members not guild.memebers. Your code should look like this:

    function addMissingJsons(message, bot) {
        bot.guilds.fetch("id").then(guild => {
            console.log(guild.members);
            guild.members.fetch().then(members => {
                console.log(members);
            });
        });
    }
    


    Since the comment worked, this is just a response for you to mark as the best answer to close the thread.