Also, try replacing soldier with friend in your for loop. You should also check on your for loop. In coding, some tiny mistakes can cause a problem; friend should be friends.
Is this Cloudrip Brawl? You have several errors and ducky is right about mismatch between friends and soldiers. Excerpts from your code:
while True:
# code
friend = hero.findFriends() # this is an array of friends, name the variable friends
# code
# check if enemy exists before searching the distance to
distance = hero.distanceTo(enemy)
if hero.gold > cost:
hero.summon("soldier")
# more logical is for friend in friends where friends is the array of friends
for "soldier" in friend: # "soldier" is a string, must be friend or if you want soldier
if enemy:
hero.command(friend, "attack", enemy) # choose between soldier or friend
else:
hero.command(friend, "move", {"x":hero.pos.x,"y":hero.pos.y}) # same as above