Jordan Pearson walked up to two officers outside the Corn Exchange in the early hours of the morning as they were taking part in an operation to target street robbers.
Leeds Crown Court heard Pearson said to the officers: “Do you want to buy some coke lads?”
The officers then told Pearson they were police and he replied: “I’m joking.”
Robert Galley, prosecuting, said the officers grabbed hold of Pearson and he “lashed out” with his arms and legs as he tried to escape.
He was searched and found in possession of three small packages containing cocaine, caffeine and paracetamol.
Pearson was interviewed and claimed the drugs in his possession was medication for gout.
Pearson, 27, of Inghams Avenue, Pudsey, pleaded guilty to offering to supply a class A drug and two offences of resisting arrest.
The court heard Pearson has previous convictions for drug supply dating back to 2005.
Adrian Pollard, mitigating, said Pearson struggled with anxiety and depression at the time of the incident, June 10 last year.
Mr Pollard said Pearson used alcohol and drugs to cope with his problems and needed help.
Pearson was made the subject of a two-year community order, during which he must take part in a 15-day programme designed to address his offending behaviour.
Judge Robin Mairs told Pearson: “This order is designed to help you.”
For the latest updates from Leeds Crown Court - join our Leeds Crime & Incidents Facebook group here