Refering back to this post of how to remove your moonroof:
sunroof removal

Panel Stay
The part I found out that rattled was the panel stay, the brackets used to mount the moonroof, and the lifter(under the panel stay). The lifter is basically a channel that makes the moonroof go up once you open it.
The lifter and the panel stay are connected by a plastic guide pin which wears. Once it wears, there is play between the lifter and the panel stay. And there is also wear between the lifter and the guide pin.
You can test to see if the culprit is the guide pin by:
1. Opening your moonroof and pushing the back of the moonroof. If you hear a HARD plastic sound - check the guide pin.
What I did was use teflon to make the guide pin thicker to reduce the amount of play between the panel stay and the lifter. As for the lifter and guide pin, I was not able to get teflon around the inside part of the pin so I used silicone. Also make sure to apply grease to the lifter channel as well as other parts of the moonroof which has play.
So far- it has cured my moonroof my annoying rattle, open and closed.
There are other sources of moonroof rattle:
1. Check first: Lack of lubrication between the sunroof seal(#10) and frame.
2. 8 10mm bolts may be loose between the panel stay and the sunroof.
3. Sunroof lining not held on fixed(#16)
I couldn't find a diagram of the panel stay and the lifter online. Just remove your sunroof and your see it.