# 用户加入群组时如何分配徽章

**URL:** https://meta.discourse.org/t/how-to-allocate-badge-when-user-joins-group/117770
**Category:** Support
**Created:** [2019年五月15日 05:58 UTC](https://meta.discourse.org/t/how-to-allocate-badge-when-user-joins-group/117770 "2019-05-15T05:58:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sat](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@sat](https://meta.discourse.org/u/sat)
#### Post date: [2019年五月15日 05:58 UTC](https://meta.discourse.org/t/how-to-allocate-badge-when-user-joins-group/117770/1 "2019-05-15T05:58:24Z")

</div>

I would like to assign badge to user when they join group. How to do that?

---

<div class="post-metadata">

### Author: ![Chaboi\_3000](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chaboi_3000/32/163015_2.png) [@Chaboi\_3000](https://meta.discourse.org/u/Chaboi_3000)
#### Post date: [2019年五月15日 08:12 UTC](https://meta.discourse.org/t/how-to-allocate-badge-when-user-joins-group/117770/2 "2019-05-15T08:12:01Z")

</div>

First enable SQL on your site by doing:

```plaintext
./launcher enter app
rails c
> SiteSetting.enable_badge_sql = true

```

Then read @sam’s guide below and follow the code:

> [@Grant a badge for all members of a group](https://meta.discourse.org/t/automatically-grant-a-badge-for-all-members-of-a-group/18147):
>
> I just created a badge for all the awesome [plugin authors](https://meta.discourse.org/badges). Creating a badge targeting a group is quite easy, just type this into the SQL box: 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 = 'GROUP\_NAME\_IN\_LOWER\_HERE' ) I will add a trigger for this at some point so granting is faster, in the mean time just go to /sidekiq/scheduler and kick off the badge job to rush it. See [Triggered custom badge queries](https://meta.discourse.org/t/triggered-custom-badge-queries/19336) for mo…

---

<div class="post-metadata">

### Author: ![sat](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@sat](https://meta.discourse.org/u/sat)
#### Post date: [2019年五月15日 15:01 UTC](https://meta.discourse.org/t/how-to-allocate-badge-when-user-joins-group/117770/3 "2019-05-15T15:01:06Z")

</div>

Thank you, will try this.

I feel it will be easy if they implement this feature in admin panel.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2022年九月24日 15:25 UTC](https://meta.discourse.org/t/how-to-allocate-badge-when-user-joins-group/117770/5 "2022-09-24T15:25:07Z")

</div>


