Discord.js Error

I’m having an issue while trying to send a DM to all members in a role. I tried looping through each member and seeing if the user has the role, and then sending the DM, but it’s saying that it “Cannot read property ‘roles’ of undefined”

I am a bit inexperienced in Node.JS since LUA is my primary language, so I’m not sure exactly how I would go about fixing this.

Code:

for (let i = 0; message.guild.members.size; i++) {
    if (message.guild.members[i].roles.has("699812761399590942")) {
        message.guild.members[i].user.send(embed)
    }
}

If you’re on v12, you’d have to use message.guild.members.cache[i] instead. Same goes for message.guild.members.cache.size