"If I had not confessed the sin in my heart, my Lord would not have listened" (Psalm 66:18, New Living Translation).
Psalm 66:8 is talking about the condition of our hearts, not some legalistic thing we must "do" to blackmail or even to lure God into listening to us. God is concerned primarily about our hearts. God listened to David because David came to him with an open, contrite, humble heart that allowed David to honestly confess his sins to his Father.
The same heart condition was in play in another "if ... then" passage when Jesus talked about the necessity of forgiving others in order for God to forgive us (Matthew 6:14-15). In other words, Jesus was saying, if your heart is so hardened that you cannot forgive others, then your heart is not yet ready to reconcile with your loving Father who is waiting patiently to forgive you and receive you back into his arms. It's about your heart being open, not about God putting a legalistic barrier in place.
When our pride gets in the way of being able to confess, repent, and forgive others, God puts us in a place where we can be broken and humbled. That's what God lovingly did with David (see Psalm 51), and he still does this today with us. It's up to us how we respond to him in these circumstances.