Hadronic molecules with a $\bar D$ meson in a medium