# Automatically Assigning Titles Based on Trust Level in Discourse

**URL:** https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365
**Category:** Support
**Created:** [March 15, 2025, 3:04am UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365 "2025-03-15T03:04:25Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![xkhalid](https://avatars.discourse-cdn.com/v4/letter/x/3ab097/32.png) [@xkhalid](https://meta.discourse.org/u/xkhalid)
#### Post date: [March 15, 2025, 3:04am UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/1 "2025-03-15T03:04:25Z")

</div>

Hi everyone,

I have set up a ranking system with custom titles, but as you know, Discourse doesn’t have a built-in way to assign a default title to all new users. So, I created a workaround where:

- New members are in **Group 1**
- Active members are in **Group 2**
- And so on…

The method I used is as follows:

```plaintext
cd /var/discourse
./launcher enter app
rails c

User.where(trust_level: 0).update_all(title: "عضو جديد")
User.where(trust_level: 1).update_all(title: "عضو جديد")
User.where(trust_level: 2).update_all(title: "عضو مشارك")
User.where(trust_level: 3).update_all(title: "عضو مبدع")

```

### The Problem

I have to run these commands manually every time a new user joins. If I run the script today and a new member posts tomorrow, they won’t get the title automatically, so I have to log in to the server and re-run the commands.

I tried automating it with a Ruby script and calling it via **crontab** , but I get an error.

I asked ChatGPT, and it told me:

> “The User model is not loaded when you run the script directly with Ruby outside of the Discourse environment.”

The issue is that I don’t have the proper **config/environment** setup inside the Discourse files.

 ![image](https://global.discourse-cdn.com/meta/original/4X/6/f/7/6f7af803de14e737f1f5dfbc4caaf604bb9895a2.jpeg)

 ![image](https://global.discourse-cdn.com/meta/original/4X/0/3/c/03c3cde3dc5875652f35ca8db0ec468efdfb12fe.jpeg)

I added It, but it didn’t work.

### My Question

Is there a way to automate this without using crontab? Or how can I properly execute a script that updates user titles without manually entering the Rails console each time?

Thanks in advance!

---

<div class="post-metadata">

### Author: ![xkhalid](https://avatars.discourse-cdn.com/v4/letter/x/3ab097/32.png) [@xkhalid](https://meta.discourse.org/u/xkhalid)
#### Post date: [March 20, 2025, 7:05pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/3 "2025-03-20T19:05:29Z")

</div>

Any help ?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 20, 2025, 7:31pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/4 "2025-03-20T19:31:55Z")

</div>

Maybe it’s possible by creating custom automation for [Discourse Automation](https://meta.discourse.org/t/discourse-automation/195773) & [Create custom Automations](https://meta.discourse.org/t/create-custom-automations/275931), but I don’t know how it works.

---

<div class="post-metadata">

### Author: ![jahan\_gagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jahan_gagan/32/501948_2.png) [@jahan\_gagan](https://meta.discourse.org/u/jahan_gagan)
#### Post date: [March 20, 2025, 8:37pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/5 "2025-03-20T20:37:27Z")

</div>

You can achieve this with a custom automation script using the `User Event` and `User Promoted Event` triggers. When a new user is created (`User Event`) or their trust level changes (`User Promoted Event`), you can trigger a script to automatically assign them a title based on their trust level.

---

<div class="post-metadata">

### Author: ![xkhalid](https://avatars.discourse-cdn.com/v4/letter/x/3ab097/32.png) [@xkhalid](https://meta.discourse.org/u/xkhalid)
#### Post date: [April 11, 2025, 11:57pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/6 "2025-04-11T23:57:27Z")

</div>

Thanks @jahan_gagan ! any help to make this script ?

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [April 12, 2025, 3:15pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/7 "2025-04-12T15:15:10Z")

</div>

Wow! Nice hacking! 👏

It does seem unfortunate that some group settings are not available for the automated groups like trust levels. It should be possible to set the user title based on the trust level group they are in but it is not.

You could try doing this using the badge system. Create a badge that is granted when a member reaches the trust level you want, and then set the “Allow badge to be used as a title”.

You can then create an automation using the “User group membership through badge” script that runs every day and updates the user’s title and flair.

 ![Screenshot 2025-04-12 at 8.14.04 AM](https://global.discourse-cdn.com/meta/original/4X/9/c/d/9cd97a584ef3a91cd1aedfa5c2891a40aff82312.png)

---

<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: [May 10, 2025, 6:45am UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/8 "2025-05-10T06:45:13Z")

</div>

Would a theme component that added this info to the post/user card be more flexible? That way users can still use the title field for other things as intended (badges, group identifiers, something custom you may want to add), and having it added by a theme component would mean they couldn’t change/remove it.

---

<div class="post-metadata">

### Author: ![xkhalid](https://avatars.discourse-cdn.com/v4/letter/x/3ab097/32.png) [@xkhalid](https://meta.discourse.org/u/xkhalid)
#### Post date: [July 19, 2025, 9:01pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/9 "2025-07-19T21:01:01Z")

</div>

Hi,

I’m trying to implement this using the badge system automation, but I’m facing a limitation.

To run the `user_group_membership_through_badge` script, I must specify a group. However, I already use the default system groups: **Trust Level 1, 2, 3, 4**. These groups are built-in and cannot be selected in the automation tool.

If I create new groups to use with this automation, I’m afraid all current members will not be carried over automatically — and I will lose the accurate mapping of users to their trust levels.

Here’s a screenshot showing the error when the group field is left empty:

 ![image](https://global.discourse-cdn.com/meta/original/4X/0/8/0/0804f1eecf20b21ddbc525ab009a8675370f70c8.png)

Is there any way to apply the badge-to-title update **without requiring a group**?  
Or is there a workaround to target the **Trust Level groups** directly within this automation?

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/a/3/aa39001a19172c4507f065ec24dfb818ed47db71.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/0/e/e/0eea83744bb4143f2c01ce98fcaf573a0d1420a3.png)

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [July 21, 2025, 12:04pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/10 "2025-07-21T12:04:21Z")

</div>

@xkhalid I’ve put together a quick plugin (also my first!) that:

 
~~ - Assigns a title to new users
 ~~-~~ Changes the title to the corresponding one with their Trust Level. E.g. TL1 → TL2: users get the TL2 title now, instead of the TL1 title.  
 ~~
- Updates user titles every 12 hours (plans to make the frequency configurable)

[https://github.com/NateDhaliwal/add-title-based-on-trust-level](https://github.com/NateDhaliwal/add-title-based-on-trust-level)

All titles configurable via settings 🙂.

---

<div class="post-metadata">

### Author: ![xkhalid](https://avatars.discourse-cdn.com/v4/letter/x/3ab097/32.png) [@xkhalid](https://meta.discourse.org/u/xkhalid)
#### Post date: [July 22, 2025, 10:05pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/11 "2025-07-22T22:05:02Z")

</div>

Thanks !

After I add this to app.yml

```bash
- git clone https://github.com/NateDhaliwal/add-title-based-on-trust-level.git

```

and rebuild, I encountered a **502 Bad Gateway** error. Any solution?  
For now, I’ve removed it from `app.yml` and everything works well.

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [July 22, 2025, 10:47pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/12 "2025-07-22T22:47:40Z")

</div>

Huh, odd. IIRC that error may sometimes appear after a rebuild, but waiting it out will solve it (or another rebuild).

---

<div class="post-metadata">

### Author: ![xkhalid](https://avatars.discourse-cdn.com/v4/letter/x/3ab097/32.png) [@xkhalid](https://meta.discourse.org/u/xkhalid)
#### Post date: [July 22, 2025, 10:52pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/13 "2025-07-22T22:52:59Z")

</div>

**Yeah, I know — but this issue only happened after I added the Git repo and rebuilt. It gave me this error.**

However, I’ll try it again later.

* * *

**What about this issue? Could it be related?**

 ![image](https://global.discourse-cdn.com/meta/original/4X/f/8/c/f8c52b2d0b7c5734e7be338ba3d6c2904d941633.png)

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [July 22, 2025, 10:53pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/14 "2025-07-22T22:53:35Z")

</div>

I’ll take another look at this, thanks for informing me.

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [July 22, 2025, 11:08pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/15 "2025-07-22T23:08:44Z")

</div>

@xkhalid could you give it a shot now? Just updated it.

---

<div class="post-metadata">

### Author: ![xkhalid](https://avatars.discourse-cdn.com/v4/letter/x/3ab097/32.png) [@xkhalid](https://meta.discourse.org/u/xkhalid)
#### Post date: [July 22, 2025, 11:47pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/16 "2025-07-22T23:47:43Z")

</div>

Thanks ! It works now.

 ![image](https://global.discourse-cdn.com/meta/original/4X/0/0/4/004cb095f2a9e3937f25362611f23ac341da32bd.png)

But it’s not reflected for all users. For example, this user is at trust level 1 and is a new user, but there’s no title assigned.

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/5/2/7522e4dd40c3227d97a5a263eeeecf14fe2d8588.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/a/6/da6186ef5d44e6c35e44aecbaf68c20b150c50fc.png)

It will take time or ?

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [July 23, 2025, 12:57am UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/18 "2025-07-23T00:57:17Z")

</div>

@xkhalid I’ve pushed a fix. Please tell me if it works now.  
Thanks!

---

<div class="post-metadata">

### Author: ![xkhalid](https://avatars.discourse-cdn.com/v4/letter/x/3ab097/32.png) [@xkhalid](https://meta.discourse.org/u/xkhalid)
#### Post date: [August 2, 2025, 12:42pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/19 "2025-08-02T12:42:37Z")

</div>

I want to thank @NateDhaliwal for his plugin !

[https://github.com/NateDhaliwal/add-title-based-on-trust-level](https://github.com/NateDhaliwal/add-title-based-on-trust-level)

It was very helpful ! and the title updated every 12 hours.

---

<div class="post-metadata">

### Author: ![joo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joo/32/334852_2.png) [@joo](https://meta.discourse.org/u/joo)
#### Post date: [August 5, 2025, 1:38pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/20 "2025-08-05T13:38:49Z")

</div>

Hi, thank you for your great plugin!

I have a more complex need:  
I’d like to set user titles automatically based on a **combination of group membership (for example: group A or group B) and trust level** (for example: TL2, TL3, etc.). For example, a user in group A with TL2 would get the title “A - TL2”, and so on.

Would it be possible to extend your plugin to support this feature, or do you have any advice on how to implement it?  
I don’t have coding experience myself, so I’d greatly appreciate any suggestions or help.

Thank you very much!

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [August 5, 2025, 2:03pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/21 "2025-08-05T14:03:04Z")

</div>

@joo Are these groups the user’s primary groups?

---

<div class="post-metadata">

### Author: ![joo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joo/32/334852_2.png) [@joo](https://meta.discourse.org/u/joo)
#### Post date: [August 5, 2025, 3:04pm UTC](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365/22 "2025-08-05T15:04:40Z")

</div>

Yes, I want to use the user’s primary group for deciding the title.

[Next page](https://meta.discourse.org/t/automatically-assigning-titles-based-on-trust-level-in-discourse/357365.md?page=2)
