async function highestRole(
  guildOrId,
  memberOrId,
) {
  const guild = await getCached("guilds", guildOrId);
  if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
  // Get the roles from the member
  const memberRoles = (await getCached("members", memberOrId))?.guilds.get(
    guild.id,
  )?.roles;
  // This member has no roles so the highest one is the @everyone role
  if (!memberRoles) return guild.roles.get(guild.id);
  let memberHighestRole;
  for (const roleId of memberRoles) {
    const role = guild.roles.get(roleId);
    // Rare edge case handling if undefined
    if (!role) continue;
    // If memberHighestRole is still undefined we want to assign the role,
    // else we want to check if the current role position is higher than the current memberHighestRole
    if (
      !memberHighestRole || memberHighestRole.position < role.position ||
      memberHighestRole.position === role.position
    ) {
      memberHighestRole = role;
    }
  }
  // The member has at least one role so memberHighestRole must exist
  return memberHighestRole;
}
/** Gets the highest role from the member in this guild */
Gets the highest role from the member in this guild
Gets the highest role from the member in this guild
async function highestRole(
  guildOrId,
  memberOrId,
) {
  const guild = await getCached("guilds", guildOrId);
  if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
  const memberRoles = (await getCached("members", memberOrId))?.guilds.get(
    guild.id,
  )?.roles;
  if (!memberRoles) return guild.roles.get(guild.id);
  let memberHighestRole;
  for (const roleId of memberRoles) {
    const role = guild.roles.get(roleId);
    if (!role) continue;
    if (
      !memberHighestRole || memberHighestRole.position < role.position ||
      memberHighestRole.position === role.position
    ) {
      memberHighestRole = role;
    }
  }
  return memberHighestRole;
}
async function highestRole ( guildOrId , memberOrId , ) { const guild = await getCached ( "guilds" , guildOrId ) ; if ( ! guild ) throw new Error ( Errors . GUILD_NOT_FOUND ) ; const memberRoles = ( await getCached ( "members" , memberOrId ) ) ?. guilds . get ( guild . id , ) ?. roles ; if ( ! memberRoles ) return guild . roles . get ( guild . id ) ; let memberHighestRole ; for ( const roleId of memberRoles ) { const role = guild . roles . get ( roleId ) ; if ( ! role ) continue ; if ( ! memberHighestRole || memberHighestRole . position < role . position || memberHighestRole . position === role . position ) { memberHighestRole = role ; } } return memberHighestRole ; }
Gets the highest role from the member in this guild
Gets the highest role from the member in this guild
// Get the roles from the member // This member has no roles so the highest one is the @everyone role // Rare edge case handling if undefined // If memberHighestRole is still undefined we want to assign the role, // else we want to check if the current role position is higher than the current memberHighestRole // The member has at least one role so memberHighestRole must exist