The best time to travel to Morocco depends on what you want to see and do while you're there. The country has a diverse landscape, from the Sahara Desert to the Atlas Mountains, so the weather can vary greatly depending on where you are. Generally, the best time to visit Morocco is in spring or fall, when the weather is more moderate. You can also visit in winter, although this is when Morocco's most popular cities, such as Marrakech and Fez, can be a bit more crowded.
If you're interested in seeing the Erg Chebbi Desert, the best time to go is during the winter months, when temperatures are cooler. Spring and fall are also great times to visit the desert.