So far, we used the hero’s name to fetch the image, description, and the hero’s abilities. This approach works for Axe, but it doesn’t work for some heroes.
One example is Shadow Fiend.
Shadow Fiend is also called Nevermore. You can see both Shadow Fiend and Nevermore in the response from the heroes endpoint.
The lores endpoint and the hero_abilities use nevermore instead of shadow_fiend. This tells us we can’t use Shadow Fiend in the API. We need to use Nevermore.
But if we use nevermore, we don’t get the Hero’s image…
Why? Because we checked the heroes endpoint for Shadow Fiend! (localized_name contains Shadow Fiend).
To get the image, we need to check against Nevermore instead.
Robustness for Hero Image
Nevermore is located in the hero’s name attribute.
To get nevermore, we can get the hero’s name property and remove the npc_dota_hero_ part. We can remove it by replacing that part with an empty string.
But the hero’s name is not Nevermore. It is Shadow Fiend. We need to insert Shadow Fiend into the DOM instead. We can do this by setting the textContent after we found the hero.