Restrict posting in a category until they "like" a topic

Just in case anyone else is interested in doing this, here is a short writeup of what I did:

  1. First, you need to enable Badge SQL through your Discourse server’s CLI:
./launcher enter app
rails c
SiteSetting.enable_badge_sql = true
  1. Next, find the ID of the topic that you want the members to interact with in order to get the badge. In my instance, the topic ID is 117

Screenshot 2026-02-27 113204

  1. Create your Custom Badge:
    1. Admin>Badges>New
    2. Name the badge whatever you want (ex. B/S/T Rule Reader)
    3. Choose a badge type, icon, and give it a description
    4. If you followed Step 1, you will see a query box where you can type in a SQL query. Paste this query (change p.topic_id = 117 to whatever your topic ID is):
      1. SELECT DISTINCT ON (pa.user_id)
          pa.user_id,
          pa.post_id,
          pa.created_at granted_at
        FROM post_actions pa
        JOIN posts p ON pa.post_id = p.id AND p.post_number = 1
        WHERE pa.post_action_type_id = 2
          AND p.topic_id = 117
          AND (:backfill OR pa.post_id IN (:post_ids))
        
    5. Make sure Run revocation query daily and Query targets posts are both checked.
    6. The trigger should be set to When a user acts on post
  2. Now we create the Automation
    1. First create a new group for the members to be added to. Mine is just named bst_rules_agreed, and it is set so only group owners and mods can see the membership. It does not need any kind of Trust Level effects.
    2. Next, go to Plugins>Automation
      1. Add a new automation
        1. Choose User Group Membership Through Badge
        2. Trigger: Recurring
          1. Recurrence: I have mine set to every 1 hour. Choose what makes sense to you.
          2. Choose a start date
        3. Script Options:
          1. Badge: Choose the badge you created above
          2. Group: Choose the group you created above

That’s it. You should now have a system that makes sure members have agreed to the rules of the category before they are able to post in the category.

My next exploration is to see if there is a way to hide all topics except the rules to everyone that isn’t in that group. But, this basic system is good enough for now.

3 Likes