RepairPal Certified shops can diagnose and repair your 2016 Toyota RAV4. They provide transparent pricing with a minimum 12-month or 12,000-mile warranty on repairs and services.
Is this vehicle still underneath factory warranty? The best choice would be to have a no-charge repair at your Toyota dealership if so!
Other than that, the only suggestion is to have testing performed. Too hard to guess without hands on diagnostic procedures.
"Moon roof" travel is is programmable and likely has gotten confused - as stated see dealer if warranty is still in effect
Local auto repair facility should be equipped to do the reset procedure using scan tool.
This may be needed even if glass appears to be fully closed!