An ex-cop who lied to the Police Integrity Commission about drug use changed his story after learning his hotel had been bugged, a Sydney court has heard.

A senior officer changed his evidence at the NSW Police Integrity Commission (PIC) after watching secretly recorded footage of himself popping an ecstasy pill, court documents show.

Former Hunter Valley inspector Matthew Dennis pleaded guilty to two counts of knowingly providing false information to the PIC following a drug-fuelled weekend on Queensland’s Gold Coast in October 2010.

An agreed statement of facts tendered to Sydney’s Downing Centre Local Court on Wednesday shows Dennis was caught up in a police surveillance sting targeting his “long time friend”, then a police superintendent.

When investigators discovered Dennis and the superintendent, who cannot be named, were planning a “boys’ trip” away with fellow serving and former officers, they set up hidden cameras and microphones in the men’s hotel rooms.

One video recorded on that weekend shows the superintendent asking Dennis if he had “had your pill” yet.

“I just had one, put it in my gullet,” Dennis replied.

Another video shows the men joking about eating hash cookies.

Dennis had told the commission during a private hearing on October 21, 2011, that he had never consumed cocaine or ecstasy, nor possessed illegal drugs.

But when he was brought back before the PIC three days later, the tapes were revealed.

“What was in your hand in the picture there now?” Dennis was asked by the PIC, after watching footage of himself put something in his mouth and wash it down with a swig from a takeaway cup.

“Well, it’s probably an ecstasy pill,” Dennis replied.

Asked why he had told the PIC that he had never seen one friend consume drugs, Dennis replied that watching the surveillance footage had jogged his memory.

“I didn’t recall previous to you showing me that (footage) that he’d actually taken drugs,” he told the PIC.

Karen Weeks, the lawyer for the former officer said Dennis had been suffering from ongoing mental health issues, including post traumatic stress, that flowed from two decades on the frontlines.

Ms Weeks made an application to have his matter discharged under Section 32 of the Mental Health Act.

“Not often is mental illness caused by decades of unselfish service to the community doing a job that we can barely imagine … scraping children off highways, picking up the parts of people who have committed suicide,” she told the court.

But Magistrate Lisa Stapleton rejected the application.

“The plea of guilty meant that when he sat in the witness box of the PIC in October 21, at the time he did it, he knew his answers were false,” she said.

The matter will return to court for sentencing in August.