It’s too easy, first add a shape ray cast, size it, position it after the player, it is the range of melee attack name it hitbox so then add a timer cooldown one shot true. So now, add a variable can_attack = true, now:
if Input.is_action_pressed("melee_attack") and can_attack:
#play here animation
can_attack = false
$CooldownTimer.start()
if hitbox.is_colliding():
for i in hitbox.get_colliders():
if i.is_in_group("Enemies"):
i.take_damage(20)
After cooldown timer timeout make the can_attack true