Generally speaking, you’re free to use someone else’s trademark so long as you use it in such a way that won’t mislead buyers into believing you are a licensee or otherwise affiliated with the trademark holder. This is called “Fair Use.” Once you to start to look for it, you’ll realize that you see examples of this everywhere. If you purchase a phone charging cable, for instance, the packaging often lists compatible phone models. Those model names are all trademarks, but the cable manufacturer can use them so long as the packaging doesn’t give buyers the impression they are buying an officially sanctioned Apple or Samsung product, etc. (That’s why manufacturers who do this sort of thing often place disclaimers on the packaging, just to be safe—“Cableco is not affiliated with Apple or Samsung.”) Another commmon example are TV commercials that make claims like “Eveready batteries last 12% longer than Duracell.”
Thus, there’s theoretically nothing stopping you from referring to “Dungeons & Dragons” in your text or even placing a notice on the cover of your product that says “compatible with Dungeons & Dragons” so long as you make certain that buyers understand this is not an officially licensed or sanctioned D&D product and you are not affiliated with WotC.