Damaging enemy teams 1.21.1

How can I damage enemy teams in a distance of 3 blocks with a command, I know it would be something like /execute as @a[distance=..3, team=!<team>] run <command> but I want it to automatically get the players team and do it to others
Continue to help post