Well, generally you'd want to have a couple of interactions in comments before sending a dm, or a fairly lengthy one.
It's really similar to meatspace tbh. You wouldn't really give your number to a rando in the checkout line, but if you ended up having a really good conversation, you might ask if they want to exchange numbers. Otherwise, you'd wait until you'd had a few conversations before suggesting a get together.
There's a degree of vibe reading necessary though. It's a lot harder for folks that haven't had a lot of social experience, or have some kind of difficulties reading cues. Unfortunately, you can't see someone checking their watch or shuffling their feet online, but there's the benefit that nobody is really obligated to respond the way in person interaction tends to feel s pressure to make a polite exit.
I'd say that as long as you approach it right, even a short interaction is okay to build from via DM for the same reason. If you lead with something making it clear you're not looking to apply social pressure, the worst that'll happen is a lack of response 99/100. You know, the usual "hope it's okay to message, feel free to ignore this if it isn't" kind of thing.