# How to mass remove PMs?

**URL:** https://meta.discourse.org/t/how-to-mass-remove-pms/303158
**Category:** Support
**Tags:** automation, sql-query
**Created:** [April 10, 2024, 12:08am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158 "2024-04-10T00:08:24Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [April 10, 2024, 12:08am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/1 "2024-04-10T00:08:24Z")

</div>

I wonder if I can search and mass remove PMs from their title or something else?

I was enabled ‘First solution accepted’ on Automation and I thought it would be sent only once but it is sent in every solution (and/or repeatedly).

Thanks 🙂

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [April 10, 2024, 12:18am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/2 "2024-04-10T00:18:09Z")

</div>

You can use bulk actions in your inbox if that is what you mean?

 ![Screenshot 2024-04-09 at 5.17.05 PM](https://global.discourse-cdn.com/meta/original/4X/9/d/c/9dc8df750bf492bb1fcc15e42db129928cc52296.png)

can probably also do via rails console.

---

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [April 10, 2024, 2:09am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/3 "2024-04-10T02:09:40Z")

</div>

_Hey, thanks for your fast reply!_

I’m asking about to delete PMs on every user, bulk option should works this way?

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [April 10, 2024, 2:54am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/4 "2024-04-10T02:54:31Z")

</div>

> [@satonotdead](#):
>
> delete PMs on every user

Oof. That seems extreme. What happened?

---

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [April 10, 2024, 3:01am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/5 "2024-04-10T03:01:49Z")

</div>

What I previouly stated:

> [@satonotdead](#):
>
> I was enabled ‘First solution accepted’ on Automation and I thought it would be sent only once but it is sent in every solution (and/or repeatedly).

We was on open-beta so _that’s not really bad_ but I truly need to remove ton of PMs 🙂

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [April 10, 2024, 3:05am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/6 "2024-04-10T03:05:18Z")

</div>

Ah. I misread it as _every PM_ rather than a bunch of PMs that fit a pattern. Do you have access to the server to run something using the Rails console? That or the API would probably work best.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [April 10, 2024, 3:20am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/7 "2024-04-10T03:20:47Z")

</div>

There should be adult hints in [Administrative Bulk Operations](https://meta.discourse.org/t/administrative-bulk-operations/118349). If you can find an example with the PostDestroyer and one that selects topics by matching the title, I think. That’s assuming you’re self hosted and can get to rails.

---

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [April 10, 2024, 3:27am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/8 "2024-04-10T03:27:55Z")

</div>

I can get into Rails, for sure! Any hint or example to begin starting with?

Thanks!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [April 10, 2024, 3:45am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/9 "2024-04-10T03:45:45Z")

</div>

Search for PostDestroyer and find something like [How to bulk delete old whispers - #2 by tshenry](https://meta.discourse.org/t/how-to-bulk-delete-old-whispers/175945/2)

---

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [April 27, 2025, 2:38am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/11 "2025-04-27T02:38:11Z")

</div>

Is that OK for you folks? Could it be improved?

```plaintext
 Topic.where("archetype = 'private_message' AND title ILIKE ?", "%something%").find_each do |t|
   PostDestroyer.new(Discourse.system_user, t.ordered_posts.first).destroy
   puts "Destroyed PM: #{t.id} - #{t.title}"
 end

```

---

<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 8, 2025, 5:22am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/12 "2025-05-08T05:22:32Z")

</div>

This should be possible using the UI, just in case that’s a preferred way.

If you use the search filter `in:all-pms`, along with the title or keywords from your automated message, that should bring them up in the search results. You can then apply the bulk actions and delete them from the results page.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [June 7, 2025, 5:22am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/13 "2025-06-07T05:22:35Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
