TypeError: Cannot read property 'members' of undefined

Hello everyone!
I was trying to code a command for my Discord bot that allowed the bot to fetch the amount of users with a certain role to do a member count.
Whenever I try to do this, my code ends up going wrong, and I get this error: TypeError: Cannot read property ‘members’ of undefined.

Here is a piece of my code:
const members = guild.members;
let ownerID = “618602359177871377”;
let membersWithRoleA = message.guild.roles.get(ownerID).members;
message.channel.send(Got ${membersWithRoleA.size} member with that role.);

var roleID = “618602359177871377”;
var size = message.guild.roles.get(roleID).guild.memberCount;

message.channel.send( Got ${size} member with that role. );

1 Like

It gives me the total amount of users in the server, no matter the role. That was one of the things I wanted, but I also wanted it by role as well.

sorry, my english is not good

Did you need something else?