Skip to content

Client.roles.cache.size => undefined | Discord.js v12 [closed]

client.roles.cache.size doesn’t seem to work for me in v12, just says that cache is undefined

Any alternatives for how I can get the total number of roles the bot is currently instantiated with across all guilds?



Client has no property called roles. This property belongs to Guild.

You can map your Guilds by roles.cache.size and get the sum of the array.

const roles = => guild.roles.cache.size);
console.log(`Total Roles: ${roles.reduce((a, b) => a + b, 0)}`);
User contributions licensed under: CC BY-SA
8 People found this is helpful