In your other thread this tutorial was mentioned. It includes how to create an AnimatedSprite2D with animations, and how to play them through code.
You say you want to play an animation, but we don’t know anything about your animation, so it’s rather difficult to give advice. Generally the animation will live on a child node, you’ll grab that with the $ symbol and use it’s play method, with the specific animation name you want. It all makes a lot more senes if you check out that tutorial
func _on_button_pressed() -> void:
$MyAnimationNode.play("A_Specific_Animation")
Try not to make duplicate threads