Imam Shafi'i (may Allah have mercy on him) said:
"Whoever desires that Allah Almighty open their heart, grant them knowledge, and bestow wisdom upon them, should practice solitude (spend time alone) and eat less.
They should also avoid the company of fools and those scholars (people of knowledge) who lack justice and proper manners."
[Manaqib ash-Shafi'i by al-Bayhaqi: 2/172]