Abu Waqid reported,

While the Messenger of Allah ﷺ was sitting in the mosque with people gathered around him, three men approached. Two of them came toward the Messenger of Allah ﷺ while the third went away. When the two stopped at the gathering of the Messenger of Allah ﷺ, they greeted him with peace. One of them saw a gap in the circle and sat in it, while the other sat behind the gathering, and the third turned away and left.When the Messenger of Allah ﷺ finished, he said, "Shall I tell you about these three men? As for one of them, he sought refuge with Allah, so Allah gave him refuge. As for the other, he felt shy, so Allah was shy with him. And as for the last, he turned away, so Allah turned away from him."

Azami 1141

Sahih

عن أبي واقد الليثي

أن رسول الله ﷺ بينما هو جالس في المسجد والناس معه، إذ أقبل نفر ثلاثة، فأقبل اثنان إلى رسول الله ﷺ وذهب واحد، فلما وقفا على مجلس رسول الله ﷺ سلما، فأما أحدهما فرأى فرجة في الحلقة فجلس فيها، وأما الآخر فجلس خلفهم، وأما الثالث فأدبر ذاهبا، فلما فرغ رسول الله ﷺ قال: ألا أخبركم عن النفر الثلاثة؟ أما أحدهم فآوى إلى الله فآواه الله، وأما الآخر فاستحيا فاستحيا الله منه، وأما الآخر فأعرض فأعرض الله عنه.

الأعظمي 1141صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Knowledge
Chapter
Encouragement to seek knowledge
Section
Whoever comes to a gathering of knowledge should sit where the gathering ends
Numbering
Jami al-Kamil 1141 (2nd edition)
Azami 1141