Discord.js guild.roles.cache.find returning undefined

First Method

Everything might not be available in cache, so you need to fetch it, the only issue is that you need to fetch via the ID.

let role = guild.roles.cache.find(r => r.name === 'ADMIN') || await guild.roles.fetch('ROLEID');

Source: https://discord.js.org/#/docs/main/stable/class/RoleManager?scrollTo=fetch

Second Method

This is a rather hacky solution, but you can fetch all roles on ready event.

client.guilds.cache.forEach(g => {      
      g.roles.fetch();
});

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top