Hi Princess_Fayette. Welcome to Discourse. Your syntax is okay but the main issue I see is the structure of your code. Let’s take it line by line.
enemy = hero.findNearestEnemy() # yes, we need this first.
hero.shield() # This is saying to shield for no apparent reason. Just shield.
# Probably not a good idea. Shielding is best when combined with a conditional for circumstances to shield.
if hero.canElectrocute(enemy): # What if there's no enemy? Code will fail. Always check if there's
hero.electrocute(enemy) # an enemy first, before telling your hero to interact with the enemy.
if enemy and enemy.type != "sand-yak": # This should be placed immediately after defining enemy
hero.shield() # and before any attack code.
if hero.distanceTo(enemy) < 10: # This won't run at all. It would work better as an else statement
hero.bash(enemy) # so that it runs during the electrocute cooldown.
Try switching things around, use elif and else conditionals, and it should work.
Check for enemy.