It highly depend on your DNS provider… if you have API access for your DNS provider, you can try search if there is an existing API script. Else, you would want to find some other DNS provider with API access and cname _acme-challenge.yourhost.tld to the DNS provider to automate the process.
Certbot has a dynamic update plugin, but Certbot's DNS plugins aren't yet easy to install on all platforms. (In particular, certbot-auto doesn't install them.) What OS are you using?
Do you run nsupdate locally? If so, you might just script two hooks (adding and removal of the TXT RR) and use those scripts with --manual-auth-hook and --manual-cleanup-hook. See for more info: User Guide — Certbot 2.7.0.dev0 documentation