A man who thought he was texting his drug dealer accidentally messaged a police captain instead, cops said.

According to police, 29-year-old William Lamberson, from Port Lucie, Florida, allegedly sent out a text looking for "green" - but mistakenly messaged the Captain of the Martin County Sheriff's Narcotics Unit.

Read: Mom Bought 12 Bags of Cocaine to Celebrate Her Daughter's 18th Birthday

It is not clear how Lamberson managed to get the number so wrong.

Rather than identify himself, the captain played along and the department shared his texts on its Facebook page.

At one point, the captain asked Lamberson if he could get him cocaine.

“I actually do man. Lol,” Lamberson allegedly answered.

After discussing the deal, they agreed to meet up.

Read: Grandfather Who Was Locked Up For Life on Marijuana Charges Walks Free After 21 Years

"Lamberson continued his electronic dialogue, and eventually, a controlled cocaine transaction was underway," police said.

On September 1, Lamberson went to meet him - but narcotics detectives were there to greet him instead. Cops shared an image of the moment he was arrested.

He was charged last week with one count of possession of cocaine with the intent to sell and was held in jail on a $40,000 bond. Court records did not list attorney information for him.

Watch Below: Model Beverly Johnson Admits to Doing Cocaine While Pregnant

Related Articles: