TypeError: Cannot read property 'cache' of undefined

iam using Discord V12 and i get this error any help

client.on(‘message’, async message => {
let guild = await message.guild.members.fetch();
let roleID= ‘644235497169748037’;
let roleID1= ‘615852982734684181’;
let roleID2= ‘615852983330013212’;
let roleID3= ‘615852992230588427’;
let roleID4= ‘722513324151144552’;

let memberCount = guild.roles.cache.get(roleID).members.size;
let memberCount1 = guild.roles.cache.get(roleID1).members.size;
let memberCount2 = guild.roles.cache.get(roleID2).members.size;
let memberCount3 = guild.roles.cache.get(roleID3).members.size;
let memberCount4 = guild.roles.cache.get(roleID4).members.size;

let memberCountChannel = guild.channels.cache.get("733035179756486737")
let memberCountChannel1 = guild.channels.cache.get("732530240420839464")
let memberCountChannel2 = guild.channels.cache.get("732530312713863178")
let memberCountChannel3 = guild.channels.cache.get("732530713898909746")
let memberCountChannel4 = guild.channels.cache.get("732530791686602833")

memberCountChannel.setName("Role1: " + memberCount)
memberCountChannel1.setName("Role2: " + memberCount1)
memberCountChannel2.setName("Role3: " + memberCount2)
memberCountChannel3.setName("Role4: " + memberCount3)
memberCountChannel4.setName("Role5: " + memberCount4)


You’re getting this error because the guild object you fetch doesn’t have a roles property. So something probably went wrong getting the data with let guild = await message.guild.members.fetch(); or the data isn’t what you thought it would be.

I recommend you write the value of guild out to the console with console.log or by whatever means Discord gives you to log debug messages :slight_smile: