Mesoporous materials are often utilized as nanocarriers to encapsulate corrosion inhibitors. However, the loading process is often complex, and the loading efficiency of corrosion inhibitors is unsatisfactory. In this research, we present a strategy for one-pot encapsulation of benzotriazole (BTA) in polypyrrole (PPy). The prepared composite material (PPy@BTA) can release corrosion inhibitors in response to acid and alkali stimulation and has the ability of near-infrared (NIR) photothermal response. Electrochemical impedance spectroscopy, scanning electron microscopy, energy dispersive spectroscopy, and wire beam electrode techniques were employed to confirm the self-healing property of the scratched coating embedded with PPy@BTA. Results indicated that the combination of NIR and pH-responsive self-healing effects endowed the composite coating with a long-term protection effect and repeatable self-healing behavior. This research broadens the scope of the use of PPy and provides new strategies for metal corrosion protection.