Is there anyway for me to program a button to switch its text once I press on it

I want to create a do not disturb button that has an outline of a crescent moon when off, and a full crescent moon when on

I know you can switch the icon of a button based on a condition but I'm not sure about text. If you're interested in icon, use an "AppleScript widget" instead of a touch bar button. Check out the preset "Minimalist Plus":

The Do Not Disturb and True Tone buttons will be visible if you press command + option + control with the Minimalist Plus preset installed and enabled.