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:8:17

And you did not kill them, but it was Allah who killed them. And you threw not, ˹O Muhammad˺, when you threw, but it was Allah who threw that He might test the believers with a good test. Indeed, Allah is Hearing and Knowing.  

You did not slay them, at Badr by your own might, but God slew them, by giving you assistance, and you threw not, O Muhammad (s), ˹against˺ the eyes of the ˹unbelieving˺ folk, when you threw, the pebbles, for a handful of pebbles thrown by a human being cannot strike the eyes of ˹every person in˺ a large troop, but God threw, by making that ˹throw˺ reach them. He did this in order to vanquish the disbelievers, and that He might try the believers with a fair test, a ˹fair˺ gift, namely, booty; surely God is Hearing, of their sayings, Knowing, of their conditions.
القرآن:٨:١٧

فَلَمْ تَقْتُلُوهُمْ وَلَٰكِنَّ اللَّهَ قَتَلَهُمْ ۚ وَمَا رَمَيْتَ إِذْ رَمَيْتَ وَلَٰكِنَّ اللَّهَ رَمَىٰ ۚ وَلِيُبْلِيَ الْمُؤْمِنِينَ مِنْهُ بَلَاءً حَسَنًا ۚ إِنَّ اللَّهَ سَمِيعٌ عَلِيمٌ  

{فلم تقتلوهم} ببدر بقوتكم {ولكنَّ الله قتلهم} بنصره إيّاكم {وما رميت} يا محمد لأعين القوم {إذ رميت} بالحصى لأن كفا من الحصى لا يملأ عيون الجيش الكثير برمية بشر {ولكنَّ الله رمى} بإيصال ذلك إليهم فعل ذلك ليقهر الكافرين {وليبلي المؤمنين منه بلاءً} عطاء {حسنا} هو الغنيمة {إن الله سميع} لأقوالهم {عليم} بأحوالهم.