Chili has that spicy flavor thanks to a substance called capsaicin. This has the function of protecting the plant against the attack of pests: thrips, white flies, aphids and other insects. Not all peppers have large amounts of this substance, so we find sweet peppers and hot peppers. Capsaicin is found in the placenta of chili and its seeds, so that by eliminating it, a large amount of this substance is eliminated.
As a curious note, I want to add that this substance does not affect birds. It is also used as an anesthetic and is an excellent remedy for nasal congestion, so consuming a little pepper can help improve this discomfort.
For more information, you can visit the following links: