If you are using stamina to determine if the hero can attack, you may want to use a stamina check in your attack command.
So if you had a function like this:
function game:on_command_pressed(command)
if command == "attack" and stamina < 0 then
game:simulate_command_released("attack")
end
end
This is just an example but it is similar to what I am using in my own game. Of course, this is assuming you have all ready set up stamina in your game so you can use methods like game:get_stamina() or game:set_stamina(). Without that, you cant really check to see if the hero can attack or not.
Generally, if I need to stop a command press under certain circumstances, I use logic gates in game:on_command_pressed() to determine if the command should be allowed or not. I'm sure the other ways mentioned work just as well, but I have never tried them.