I think there is no API to know if the desktop is in Do Not Disturb mode, because apps are supposed to send notifications as usual, it’s just that the user won’t be disturbed by them and can see the notifications afterwards.
What are you trying to achieve? What’s your goal by detecting the Do Not Disturb?
The fact that the system can be introspected (with D-Bus or other methods) when desktop settings are modified doesn’t mean that there is a guaranteed stable API for it.
It works by showing a window in specified intervals with some break / stretch idea. For MacOS / Windows I have a functionality where people can choose to not be shown breaks in DND mode. I want to have the same for Linux.
Here’s my PR where I am adding this (currently working on KDE, XFCE): basically when user enables DND, I pause showing of breaks and when DND ends breaks are resumed
That’s a solution, running the gsettings command in a sub-process. Probably good enough
Otherwise I don’t know if you have access to the GSettings API, part of the GIO library, from the programming language that you use. You can check https://gtk.org/ to see the language bindings.
Edit: GSettings has an introspectable part in its API, to look if the schema and key is present. Otherwise if you try to get a value directly, and the gsettings schema or key is not present on the system, the program crashes. In C it’s the g_settings_schema_has_key() function.