How to add a role to a user in a specific guild

So I have this current code:

const mutualGuilds = bot.guilds.cache.filter((guild) => {
  return guild.members.cache.has(message.author.id);
});

if (mutualGuilds.roles.cache.has("guildid")) {
  if (mutualGuilds.users.cache.has(user.id)) {
    let userInGuild = mutualGuilds.users.cache.find(user.id).roles.add("roleid");
  }
}

And when I try the command it outputs: Cannot read property 'cache' of undefined

If someone could help that would be amazing since my bot is on release today.

Leave a Comment