The Messenger of Allah ﷺ said, "When one of you grows drowsy, let him lie down until the sleepiness leaves him, for if he prays while drowsy, he may intend to seek forgiveness and end up cursing himself instead."
حدثنا ابن نمير حدثنا هشام عن أبيه
قال رسول الله ﷺ إذا نعس أحدكم فليرقد حتى يذهب عنه النوم فإنه إذا صلى وهو ينعس لعله يذهب يستغفر فيسب نفسه
Its isnad is sahih. Bukhari related it, 1/313, no. 212, in wudu, Muslim, 1/542, no. 786, in the travelers, Tirmidhi, 2/186, no. 355, and he said, hasan sahih, and Abu Dawud, 2/33, no. 310, both of them in prayer.