The Prophet ﷺ said, "The supplication of any one of you will be answered as long as he does not become impatient and say, 'I prayed but my prayer was not answered.'"
حدثنا الأنصاري حدثنا معن حدثنا مالك عن ابن شهاب عن أبي عبيد مولى ابن أزهر
عن النبي ﷺ قال يستجاب لأحدكم ما لم يعجل يقول دعوت فلم يستجب لي
Agreed upon (by Bukhari and Muslim). Bukhari transmitted it in the Book of Supplications, chapter "A servant's supplication is answered as long as he does not grow impatient," no. 6340, and Muslim, no. 2735, both from the hadith of Malik through this same chain, and it is found in Muwatta, 1/213.There is also a version on this subject from Anas [Ahmad, 3/193, 210].