The gift of discernment is a gift of the Spirit. Ammon possessed this gift in such great degree that he was able to discern the thoughts of Lamoni. “Not only can the power of discernment distinguish good from evil (Moro. 7:12-18), the righteous from the wicked (D&C 101:95), and false spirits from divine (D&C 46:23), but its more sensitive operation can also make known even ‘the thoughts and intents of the heart’ of other persons (Heb. 4:12; D&C 33:1).” (The Encyclopedia of Mormonism, edited by D. Ludlow, p. 384)
Boyd K. Packer
"(having quoted Alma 18:18) This power of discernment is a very real spiritual gift. It is often conferred as a blessing upon men ordained as bishops, stake presidents, and so forth. Many can bear witness to the fact that they do not have to hear or to see all that they know, that they can discern thoughts when the purpose of their office is served.
“I have often thought, as members of the Church come to us as General Authorities for counsel, that they are not aware that sometimes their words are in one avenue and their thoughts are in another, and yet it is important that we learn that we cannot hide our thoughts. You can’t hide them. Sooner or later, they will be known; they will express themselves in actions. ’As [a man] thinketh in his heart, so is he.’ (Proverbs 23:7.) As a man thinketh in his heart, so he does.” (That All May Be Edified, p. 35)