Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:31:12

And We had certainly given Luqman wisdom ˹and said˺, "Be grateful to Allah." And whoever is grateful is grateful for ˹the benefit of˺ himself. And whoever denies ˹His favor˺ - then indeed, Allah is Free of need and Praiseworthy.  

And verily We gave Luqmān wisdom, comprising knowledge, religiousness, and right-mindedness in speech; his many wisdoms are well-known. He used to give legal opinions ˹in matters of religion˺ before David was summoned ˹to prophethood˺, but lived on into the latter’s summoning. He then took to acquiring knowledge from him ˹David˺ and refrained from giving ˹any more˺ legal opinions, explaining this thus: ‘Should I not be content if someone ˹like the prophet David˺ has spared me the trouble?’ He was once asked, ‘What is the worst kind of person?’ He said, ‘The one who does not care that people should see him doing evil’. In other words, ˹We gave him wisdom˺ and We said to him: ‘Give thanks to God, for the wisdom that He has given you. Whoever gives thanks only for his own sake, because the reward for his gratitude shall be his, and whoever is ungrateful, for a grace, then surely God is Independent, ˹without need˺ of His creation, Praised’, in what He does.
القرآن:٣١:١٢

وَلَقَدْ آتَيْنَا لُقْمَانَ الْحِكْمَةَ أَنِ اشْكُرْ لِلَّهِ ۚ وَمَنْ يَشْكُرْ فَإِنَّمَا يَشْكُرُ لِنَفْسِهِ ۖ وَمَنْ كَفَرَ فَإِنَّ اللَّهَ غَنِيٌّ حَمِيدٌ  

{ولقد آتينا لقمان الحكمة} منها العلم والديانة والإصابة في القول، وحكمه كثيرة مأثورة، كان يفتي قبل بعثة داود وأدرك بعثته وأخذ عنه العلم وترك الفتيا وقال في ذلك: ألا أكتفي إذا كفيت، وقيل له أي الناس شر؟ قال: الذي لا يبالي إن رآه الناس مسيئاً {أن} أي وقلنا له أن {أشكر لله} على ما أعطاك من الحكمة {ومن يشكر فإنما يشكر لنفسه} لأن ثواب شكره له {ومن كفر} النعمة {فإن الله غني} عن خلقه {حميد} محمود في صنعه.