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:3:123

And already had Allah given you victory at ˹the battle of˺ Badr while you were few in number. Then fear Allah; perhaps you will be grateful.  

When they were defeated, the following was revealed as a way of reminding them of God’s favour: God already gave you victory at Badr, a location between Mecca and Medina, when you were contemptible, few in number and weapons. So fear God, in order that you might be thankful, for His blessings.
القرآن:٣:١٢٣

وَلَقَدْ نَصَرَكُمُ اللَّهُ بِبَدْرٍ وَأَنْتُمْ أَذِلَّةٌ ۖ فَاتَّقُوا اللَّهَ لَعَلَّكُمْ تَشْكُرُونَ  

ونزل لما هزموا تذكيرا لهم بنعمة الله {ولقد نصركم الله ببدر} موضع بين مكة والمدينة {وأنتم أذلة} بقلة العدد والسلاح {فاتقوا الله لعلكم تشكرون} نعمه.