Award a non-custom badge through the console

:bookmark: This guide explains how to award a non-custom badge through the Discourse console.

:person_raising_hand: Required user level: System Administrator

:warning: Console access required

In specific scenarios, you might need to manually award a default Discourse badge to a user from the console. For example, a user may not receive the "Enthusiast" badge due to visiting a forum for 10 consecutive days, possibly due to time zone between the user’s local time and the server’s UTC time.

This documentation provides a step-by-step guide on manually awarding non-custom badges using the Rails console, ensuring these badges won’t be auto-revoked.

Checking auto-revocable badges

Before awarding a badge, ensure that it will not be auto-revoked by the system. Run the following command in the Rails console to get a list of such badges:

Badge.where(auto_revoke: false).pluck(:name)

This command will display a list of non-auto-revocable badges, including:

  • "First Flag"
  • "Thank You"
  • "Gives Back"
  • "Empathetic"
  • "Out of Love"
  • "Higher Love"
  • "Crazy in Love"
  • "Aficionado"
  • "Devotee"
  • "Enthusiast"
  • "Reader"
  • "Anniversary"
  • "Appreciated"
  • "Respected"
  • "Admired"

Awarding a badge

To grant a badge from this list, follow these steps:

  1. Find the user by username:

    Run the following command, replacing enthusiastic_user with the actual username:

    user = User.find_by(username: 'enthusiastic_user')
    
  2. Locate the badge by name:

    For example, to find the “Enthusiast” badge, use:

    badge = Badge.find_by(name: "Enthusiast")
    
  3. Grant the badge to the user:

    Finally, award the badge to the user with this command:

    BadgeGranter.grant(badge, user)
    

Last edited by @SaraDev 2024-11-13T23:01:05Z

Check documentPerform check on document:
17 Likes