Restless Dead Level Help Python

I can’t kill all of the skeletons.

while True:
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    item = hero.findNearestItem()
    flag = hero.findFlag("green")
    if friends:
        for friend in friends:
            if enemy:
                hero.command(friend, "attack", enemy)
            hero.command(friend, "defend", {"x": 44, "y": 41})
    if hero.gold >= 70:
        hero.summon("soldier")
        hero.summon("griffin-rider")
        
    if flag:
        hero.pickUpFlag(flag)
    if item:
        hero.move(item.pos)
    if enemy:
        if hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
        hero.attack(enemy)
    

have you ever tried attacking the enemy? although you do attack you only do if you cast chain lightning so it only happens every once in a while.

I don’t think that’s the problem:
image

They attack the enemy after checking if they canCast chain lightning, regardless of whether or not they can cast it.