Sorry it might not be super clear, so let me explain it.
ATM we only have a trigger for granted badge, which means we can calls scripts when a user is awarded a badge. But we don’t exactly have what you currently ask for a script to grant a badge
which would be triggered on some event (joining a specific group? ). As explained, our best solution so far is Triggered custom badge queries