Hey Helga,
If you want to automatically grant a badge, the best way to do this is via the SQL Query for the badge.
This can be found In admin->badges
Then scroll down to find the SQL query.
If you search through meta.discourse.org you might be lucky enough to find someone has already written the query you are looking for.
My favourite query grants a badge when someone joins a group. The example below grants the badge within 24 hours of the person joining the “discourse-admin” group
select user_id, created_at granted_at, NULL post_id
from group_users
where group_id = (
select g.id from groups g where g.name = 'discourse-admin'
)
I use the following settings with the query for the badge


