AnIdiotsGuide/discordjs-bot-guide

Does this actually get the role object or does it just check if the role exists ?

derpr opened this issue · 1 comments

derpr commented
// get role by name
let myRole = message.guild.roles.cache.find(role => role.name === "Moderators");

From my understanding, this doesn't get a role object. The find method just returns a boolean value of the role's existence.

Collection#find returns the first value from the collection for which the function you provided returns true, so in the above case myRole will be a role object (or undefined). There is Colection#some which does exactly what you're talking about. See this to learn about Collection methods.