Psa 34:18 The LORD is near to the brokenhearted and saves the crushed in spirit.
The Lord draws near those whom He has exposed the conditions of their heart by His righteousness. Isaiah and David are perfect examples. Isaiah in a vision saw the Lord. His holiness exposed the malady of sin in Isaiah’s life, his cry, Isa 6:5 “…Woe is me! For I am lost; for I am a man of unclean lips, …; for my eyes have seen the King, the LORD of hosts!” He was in a way saying “I am a great sinner, as many other ways, so particularly by my lips”
David on the other hand was confronted by Nathan for committing adultery with Bathsheba and murdering Uriah. Rather than justify, “David said to Nathan, “I have sinned against the LORD.” …” (2Sa 12:13) In both cases broken-hearted, crushed under the weight of their sins, God came near cleansed, saved and restored them.
Those whose prayers God will hear are they of a broken heart and a contrite spirit (that is, humbled for sin and emptied of self). Jas 4:6-8, “6… “God opposes the proud but gives grace to the humble.”…8 Draw near to God, and he will draw near to you. Cleanse your hands, you sinners, and purify your hearts, you double-minded.“