# Automatically append staff notice to user posts

**URL:** https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123
**Category:** Development
**Tags:** post-notices
**Created:** [February 5, 2023, 4:33pm UTC](https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123 "2023-02-05T16:33:23Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![jhealey](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@jhealey](https://meta.discourse.org/u/jhealey)
#### Post date: [February 5, 2023, 4:33pm UTC](https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123/1 "2023-02-05T16:33:23Z")

</div>

Our system generates accounts for posting announcements, we were wondering if there was a way to add a separate staff notice that has its own icon that automatically appends to these posts so we can explain that it is an auto-generated account? Even by userid/name, or group works.

---

<div class="post-metadata">

### Author: ![Lhc\_fl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lhc_fl/32/268115_2.png) [@Lhc\_fl](https://meta.discourse.org/u/Lhc_fl)
#### Post date: [February 6, 2023, 9:01am UTC](https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123/2 "2023-02-06T09:01:35Z")

</div>

I think you can achieve this with theme components. For example, this code does what you need:

```javascript
<script type="text/discourse-plugin" version="0.8">

const { iconHTML } = require("discourse-common/lib/icon-library");

const bot_id = 128856; // or some else
api.decorateWidget("post:before", (helper) => {
    if (helper?.getModel()?.user_id !== bot_id) {return;}
    return helper.h("div.post-notice",[
        helper.rawHtml(iconHTML("shield-alt")), // icon name
        helper.h("p", "this is a bot"), // text
    ]);
});

</script>

```

---

<div class="post-metadata">

### Author: ![jhealey](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@jhealey](https://meta.discourse.org/u/jhealey)
#### Post date: [February 14, 2023, 4:02pm UTC](https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123/4 "2023-02-14T16:02:16Z")

</div>

Hi there!

I’ve tried using JS to auto-append a staff notice to an auto-generated account if it is a member of the group “autogenerated” but I’m not sure where I’m going wrong.

```plaintext
<script>
   window.onload = function() {
     const { groupMembers } = await discourse.groups.getMembers({
       group_name: 'autogenerated'
     });

     if (groupMembers.includes(helper.getModel().user_id)) {
       return helper.h('div.post-notices', [
         helper.rawHtml(iconHTML('shield-alt')),
         helper.h('p', 'This account is auto-generated and should be considered as a bot. The account is not monitored by Staff.')
       ]);
     }
   }
 </script>

```

I’ve put the code in the “Head” part of our component, however, it’s not running. I’m not sure if it isn’t calling the function correctly, or if my IF statement suddenly isn’t being met.

---

<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: [February 19, 2023, 5:46pm UTC](https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123/5 "2023-02-19T17:46:07Z")

</div>

Hi @jhealey 🙂 I’ve slipped your post into the existing topic as they seem very similar questions. 👍

---

<div class="post-metadata">

### Author: ![Decorbuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/decorbuz/32/235124_2.png) [@Decorbuz](https://meta.discourse.org/u/Decorbuz)
#### Post date: [February 19, 2023, 6:08pm UTC](https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123/6 "2023-02-19T18:08:15Z")

</div>

> [@JammyDodger](#):
>
> Hi @jhealey 🙂 I’ve slipped your post into the existing topic as they seem very similar questions. 👍

You might want to lock the other topic then. I probably should’ve replied to this topic instead… 😅

---

<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: [February 19, 2023, 6:13pm UTC](https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123/7 "2023-02-19T18:13:26Z")

</div>

I relied too much on the auto tools doing it and didn’t check. 🙂 I have removed the other topic. 👍

---

<div class="post-metadata">

### Author: ![Decorbuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/decorbuz/32/235124_2.png) [@Decorbuz](https://meta.discourse.org/u/Decorbuz)
#### Post date: [February 19, 2023, 6:14pm UTC](https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123/8 "2023-02-19T18:14:50Z")

</div>

> [@JammyDodger](#):
>
> I relied too much on the auto tools doing it and didn’t check. 🙂 I have removed the other topic. 👍

Thanks! 😊

> [@jhealey](#):
>
> Hi there!
> 
> I’ve tried using JS to auto-append a staff notice to an auto-generated account if it is a member of the group “autogenerated” but I’m not sure where I’m going wrong.
> 
> ```plaintext
> <script>
> window.onload = function() {
> const { groupMembers } = await discourse.groups.getMembers({
> group_name: 'autogenerated'
> });
> 
> if (groupMembers.includes(helper.getModel().user_id)) {
> return helper.h('div.post-notices', [
> helper.rawHtml(iconHTML('shield-alt')),
> helper.h('p', 'This account is auto-generated and should be considered as a bot. The account is not monitored by Staff.')
> ]);
> }
> }
> </script>
> 
> ```
> 
> I’ve put the code in the “Head” part of our component, however, it’s not running. I’m not sure if it isn’t calling the function correctly, or if my IF statement suddenly isn’t being met.

If you’re using `await`, your function must be `async`.

---

<div class="post-metadata">

### Author: ![jhealey](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@jhealey](https://meta.discourse.org/u/jhealey)
#### Post date: [February 19, 2023, 9:57pm UTC](https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123/9 "2023-02-19T21:57:01Z")

</div>

I don’t know how I didn’t notice that! Thank you! It’s working now 🙂

---

<div class="post-metadata">

### Author: ![Decorbuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/decorbuz/32/235124_2.png) [@Decorbuz](https://meta.discourse.org/u/Decorbuz)
#### Post date: [February 20, 2023, 1:52am UTC](https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123/10 "2023-02-20T01:52:37Z")

</div>

> [@jhealey](#):
>
> I don’t know how I didn’t notice that!

It’s okay! Once in a while, we _all_ make oversights like that.

> [@jhealey](#):
>
> Thank you! It’s working now 🙂

You’re welcome! ❤

---

<div class="post-metadata">

### Author: ![rassilon1963](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rassilon1963/32/354656_2.png) [@rassilon1963](https://meta.discourse.org/u/rassilon1963)
#### Post date: [March 11, 2024, 2:28pm UTC](https://meta.discourse.org/t/automatically-append-staff-notice-to-user-posts/254123/11 "2024-03-11T14:28:32Z")

</div>

all these hacks are nice and all, but this should be a built-in feature in some way or another.
