Apple - Persistent badge on Messages app icon in macOS High Sierra

None of the other answers really solved it for me. After killing the Dock or signing out and back in, I'd have the badge return eventually.

So in Finder I went to ~/Library and searched for the listed phone number. It showed me a file in ~/Library/Messages/Archive/yyyy-mm-dd/ that was named for the phone number. Deleted the file and then killed the dock (by executing killall Dock in the Terminal) and the badge was gone instantly.

I have also figured out the cause: deleting a message on your iPhone or iPad without reading it. It's always an automated message with a 2FA code or something, and that's because I could see the code and typed it in and then deleted the thread later because I always trash that junk.

I've had two cases where that bubble remains even after I signed out of Messages entirely and then signed out of my AppleID everywhere (FaceTime, iCloud, App Store, iTunes, etc... which is everywhere I can think of - perhaps I missed a spot) so I'm thinking there's some chance there's a bug in the database(s) that track this and clearing that will be quite difficult.

On these two cases, I just set up a temporary admin account and logged out of the main account. Then I did a proper backup (Time Machine or other) and deleted the offending user account. Once you clear the home folder /Users/whatever - then I made a new user account with the same short name (or different if you please) and copied back only the working files - not the settings.

This has fixed the Messages count for both cases - so it wasn't really a problem online - more of a local database corruption that I wasn't clever enough to pick apart and locate what set of files or database held the wrong unread badge count.

It's a very indirect fix and lots of work, but the new account olympics did help when I don't know precisely how to zero the count.