In order to obtain reliable Compton spectra using high-energy photons, the scattered beam must be free of parasitic photons, because of the weakness of the double-differential inelastic cross section. The purpose of the device presented in this paper is to remove photons scattered by air, the sample holder or any other stopper. It has been tested on ESRF beamline 2, which is devoted to materials science.