The Meaning of Life, the Universe, and Everything.
!!This will need to be a datapack!!
You'd be able to do it, by:
1. as each player, summoning a marker entity at themselves. Then, as each marker:
1. give the nearest player a tag (doesn't matter which one, since you'll have to remove it at the end of this)
2. copy the spawn coordinates of the player to their own position
3. check if the block at their location is a bed. (this would look like the command you gave)
4. if not, run whatever function you want. You can target the player with the tag you gave in step 1.
5. Remove the tag from the player, and kill the marker.
I'll add some commands on how this would work tomorrow / if I remember.
This might not work, due to the spawn location not being loaded. If it is, and you want that to not be an issue, you can add a second file that adds a tickingarea/removes the old one whenever a player changes their spawnpoint.
You'll get issues when in a different dimension, but you can fix that by teleporting to the overworld.