Dust attenuation of the nebular regions and optical emission lines of $z\sim2$ star-forming galaxies