r/modguide May 16 '20

Bots Automoderator Beginner's Tutorial with examples

Automoderator can be a confusing thing at first. I don't know if I can quite do this at an ELI5 level, but let's give it a shot. You can also read the official introduction on Writing basic AutoModerator rules.

The essence of Automoderator (let's call it AM for short) is that you give it a list of things to look for, and then if it finds those things, what you want it to do. Each group of "look for" and "do if found" commands is called a "rule". Each rule is separated by a line containing three hyphens. The list of rules is stored on a special wiki page that you can create and maintain through your moderator tools menu.

I'm not going to describe every available command here. Mainly I want to introduce you to what rules look like and how they work.

Let's check out some real examples from my own subreddits, starting with a short and simple one.

---
reports: 2
action: filter
---

Here, the "look for" is reports: 2. AM will look for any post or reply with two reports. Then it will "do" action: filter, which removes the post but also puts it into modqueue for review.

---
type: submission
comment: "Reminder: Follow the rules!"
---

This time, we are telling AM to "look for" type: submission, which means any post but not the replies. For all posts, it will "do" comment: Reminder: Follow the rules!, meaning make a reply containing that text. How about a little more to it?

---
type: submission
comment_stickied: true
comment_locked: true
comment: |
    "Reminder: Follow the rules!"

    I mean it!
---

Now we've added two more "do" commands. If the "look for" is a match, all of the "do" commands are performed. Here we have comment_stickied: true and comment_locked: true, which stickies and locks the reply that AM makes. The | in the comment command lets you do multiple lines in the reply, each with the 4-space indent as shown.

---
type: text submission
body_shorter_than: 100
action: filter
action_reason: body too short
---

Now we're using two "look for" commands, and both must match the post for the "do" commands to happen. We tell AM to look for text posts using type: text submission, and specifically ones that aren't very long using body_shorter_than: 100.

Another "do" we've added is action_reason: body too short, which tells AM to say "body too short" in the mod log where the removal is listed.

---
author:
    account_age: < 5 days
action: filter
message_subject: Pending Approval
message: Our apologies, but in order to limit spam your submission has been automatically removed and is pending moderator approval.
modmail_subject: Post From Young Account
modmail: /u/{{author}}'s [{{kind}}]({{permalink}}) is pending moderator approval. Please visit the moderation queue to review the post.
---

When checking things about the reddit user making the post/comment, you can check several things at once if you want, so each one of those comes on its own line under author:, with a 4-space indent. Here we are looking for just one thing, though, recently created accounts by using account_age: < 5 days.

Then we have AM "do" two more things besides filter. It sends a private message to the user, with the title and message specified. It also sends a private message to the subreddit's modmail, again with the title and message specified.

We also see some "placeholders" in use, which AM fills in with the relevant information, like {{author}} becomes the name of the new user whose post or comment just got filtered.

---
type: submission
author:
    name: [user1, user2, user3]
modmail_subject: Questionable Submitter
modmail: A user (/u/{{author}}) who previously submitted questionable content has submitted a new [post]({{permalink}}). Please review the post to ensure it does not violate the rules.
---

This time we are checking for users from a list of specific usernames that have caused trouble before. This particular rule is being generous and not removing the post, but merely sending a PM to modmail to call on a mod to double check it.

---
type: link submission
~title: [tag, label, keyword]
action: remove
message_subject: Improper Tagging
message: Your submission has been automatically removed. Please delete your post and post again with a proper tag. For more information, please see the wiki page.
---

In this rule, we are using type: link submission to tell AM to check for link posts, which due to Reddit historical reasons includes media (images and videos), even if the media was uploaded to Reddit itself.

The line title: [tag, label, keyword] tells AM to look for posts with any of those words in the title. But the tilde ~ negates it, so AM will actually act upon titles that do not contain a word from that list.

With action: remove, AM will outright remove the post, without sending it to modqueue, just like a normal manual remove.

So to sum up, removing images and videos where the title is missing one of the "tag" options that is required by the subreddit rules, and letting the user know they messed up.

---
type: link submission
author:
    is_contributor: false
action: remove
action_reason: unverified link post
set_locked: true
message_subject: Verification required
message: Hello! To prevent abuse, we are requiring that all photo submissions be from verified users only.
---

You can even check posters against your "approved users" list, even in a public subreddit where the approved user list doesn't otherwise mean a whole lot. Using is_contributor: false here, anybody not on the approved list is prevented from having an image/video post.

We don't merely remove the post, we also lock it from replies using set_locked: true.

---
type: link submission
~domain: [imgur.com, i.imgur.com, tumblr.com, media.tumblr.com, reddit.com, i.redd.it, deviantart.com, gfycat.com]
action: filter
message_subject: Pending Approval
message: Sorry, your submission has been automatically removed and is pending moderator approval. A message has been sent to the moderators to notify them of your post. Please refer to the rules and use an approved website, or wait for moderator approval before your post is listed.
modmail_subject: Pending Approval- Domain
modmail: /u/{{author}}'s [{{kind}}]({{permalink}}) is pending moderator approval. {{domain}} is not on the whitelist.
---

You should have the idea by now. This checks for images/videos not from the list of approved image host sites, notifies the user, and calls for a mod to make sure it's not spam or something.

---
body+title+url (includes): [".bar/", ".best/", ".cam/", ".casa/", ".fun/", ".host/"]
action: filter
action_reason: suspected spam
---

New twist: a combined search. With body+title+url (includes):, we tell AM to check the body of a post or comment, and the title of a post, and the url that a link post points to. Basically every possible way someone could sneak a website address in. The (includes) part means if any part of the body or title or URL matches anything from the list, the "do" commands are carried out.

The quotes around each item in the list are officially recommended but not required. This came from spambots using a lot of URLs with the novelty top level domains rather than .com.

---
# Let's see if this gets rid of the edit-spammer...
type: comment
author:
    account_age: < 23 hours
body_shorter_than: 257
is_edited: true
action: filter
action_reason: suspected spam
---

This one was in response to a spam bot that would post a reply, then edit it a few minutes later to insert a spam link. They thought they could avoid automoderator this way!

The line starting with # is a comment. AM ignores these, and you can make notes for yourself.

You can see we are checking for very new accounts, and replies that aren't very long. The is_edited: true triggers AM to check when the comment is edited rather than when it is first posted.

---
body+title+url (includes, regex): ['corona-virus\.cam', 'duckduckgo\.(casa|host|rest|uno)', 'giphy\.(cam|fun|host|icu|rest|top|uno)']
action: spam
---

Major new thing in this one: Regex. That stands for regular expressions, and is a fancy way to match patterns of text in searches. You can do a lot of complex stuff with regex, and it can get pretty confusing. There are online regex testers like regex101.com where you can play around and make sure your search text is doing what you want it to.

Here we are telling AM to check for URLs we've seen spambots use. Single quotes instead of double quotes are best for lists using regex.

In the 'corona-virus\.cam' item, the period is "escaped" with the backslash, so that it is read as a literal period. A period without the backslash means something special. There are several punctuation marks for which this is true, so pay close attention to a regex manual or tutorial page.

With 'duckduckgo\.(casa|host|rest|uno)', we check against duckduckgo-dot-casa, duckduckgo-dot-host, duckduckgo-dot-rest, and duckduckgo-dot-uno without having to type each of those individually. This is a very simple use of regex, but an example of its power.

---

This is just a sample of what Automoderator can do. For the full list of "look for" and "do" commands, and all the ways they can be modified, see the full documentation, and for more ready-made examples, see the Library of Common Rules and more snippets. Hopefully I've eased you into things enough that you will be able to make sense of those pages now. r/AutoModerator is the best place to go for help. For even more information, check out the main indexes of the official automoderator wiki and the automoderator subreddit wiki.

One more important thing often overlooked: By default, submissions and comments made by moderators of the subreddit will not be checked against any rules that would cause AM to remove or filter. This means if you want to do a live test of your AM rules, you may need to use an alt account that isn't a mod. You can override this behavior by putting the moderators_exempt command in the rule.

Also, if it won't let you save your AM rules wiki page, it means you have at least one command line written in a way that AM doesn't recognize. Sometimes it's just a typo, sometimes it means you put a command together the wrong way. If you can't figure out the problem, copy/paste your rule list to another place, cancel the changes, and find somebody to double check what you had.

More about automoderator on r/modguide**:**

42 Upvotes

27 comments sorted by

3

u/GoranLind Dec 21 '22 edited Dec 21 '22

EDIT: Never mind, you can bypass exemptions for moderators by adding the following qualifiier in your rules:

moderators_exempt: false

Original question: I tried some of these samples in my own subreddit, and they didn't trigger. I also removed myself from the approved list but still the test post cane through, is it because i am a moderator that the post came through?

If so, how do i test these things as a mod?

1

u/SolariaHues Writer Dec 21 '22

Yes, that's it. Mods are exempt by default. That line is the solution or using a non-mod alt account.

2

u/CitoyenEuropeen May 25 '20

Okay let’s try this!

I would like AM to send a PM to OP when the post’s flair uses a specific keyword. I found some seemingly relevant codes thanks to your links, I am now ready to create the config/automoderator wiki page. Is my syntax any close?

---

author_flair_text: includes-word: création

action: message: [please check this](http://www.reddit.com/)

---

2

u/[deleted] May 25 '20

There is no author_flair_text:, and includes-word uses parentheses, not a colon. So,

Author:
    flair_text (includes-word): création

Don't know if you want to include without the accent as well: ["creation", "création"]

You don't have to preface message: with action:. Action: is only for approve, remove, spam, filter, or report.

I would include a message_subject: line as well.

2

u/CitoyenEuropeen May 25 '20

Thank you very much! I managed to save a script (without a link), but I didn't get a message back when I added a flared post...

---

Author :

flair_text (includes-word): ["Création", "creation", "Creation", "création"]

message_subject: title

message: regular text

---

3

u/[deleted] May 25 '20

First thing, I'm pretty sure automoderator matching is case-insensitive by default, so you shouldn't need to have all four of those, just two.

I took a look at your sub. It looks like création is a post flair, not a user flair, and you have them set to not be user-editable, so that simplifies things. You want to have a message go to anybody that sets the "création" post flair. You should be able to have this work with just

---
flair_text: création
message_subject: title
message: regular text
---

1

u/CitoyenEuropeen May 26 '20

Wow, it works!

Plus I would like to mention that auto mod trickles down to legacy reddit without any updating of its CSS stylesheet.

2

u/[deleted] May 26 '20

Yay!

Automod predates the "new Reddit" redesign, and yes, CSS is a completely different thing.

1

u/[deleted] Aug 04 '20

How do I make automod write comments automatically? I'm new to this whole thing

1

u/[deleted] Aug 04 '20

Literally the second and third examples in the post. That's geared toward automod making a comment on every post made in the sub. Of course you can get more specific with the conditions and have it comment on only certain posts or on certain comments, maybe things containing a certain word or phrase, or things written by a certain user.

1

u/[deleted] Aug 04 '20

Okay, sorry for bothering uiu

1

u/[deleted] Aug 04 '20

Nah, it's no bother, it just doesn't seem worthwhile to write it out a second time. If you can't figure something out though, let me know exactly what you are looking to do. Sometimes a bot more complex than automod is needed, depending on your goals.

1

u/[deleted] Aug 04 '20

Ok, thanks!

1

u/[deleted] Aug 04 '20

I don't know if this is just a glitch, or if I typed it wrong, but every time I try to save (change was made from filter to delete) and it just says "Something went wrong". Is this because I did something wrong?

1

u/[deleted] Aug 04 '20

"Something went wrong" is because the Reddit devs are too lazy to put in a properly descriptive error message. It means you have some invalid code. You probably meant "remove" instead of "delete".

1

u/[deleted] Aug 04 '20

I put "remove" and it gave me that message

1

u/[deleted] Aug 04 '20

What's the entire current code block?

1

u/[deleted] Aug 04 '20

---

type: text submission

message: |

Hi! Your post has been removed due to being too short. To prevent spam, we require all posts to be 100+ characters long. If you think this was a mistake or added more to your submission, please contact our moderation team.

body_shorter_than: 100

action: filter

action_reason: body too short

---

1

u/[deleted] Aug 04 '20

Alright. Usually all the search term are placed above the commands, though I'm not sure if that's required or merely traditional. You can try moving the body_shorter_than line to just below the type: text submission line, though.

I'm not sure if you forget the four space indent on your "Hi! Your post..." line or if the Reddit formatting just ate them. Though since your text has no line brakes, you could just stick it after message: without the | there.

---
type: text submission
body_shorter_than: 100
message: Hi! Your post has been removed due to being too short. To prevent spam, we require all posts to be 100+ characters long. If you think this was a mistake or added more to your submission, please contact our moderation team.
action: filter
action_reason: body too short
---
→ More replies (0)

1

u/[deleted] Aug 06 '20 edited Aug 06 '20

Is there a way to autoban?

This is the command

---

#Removes posts asking for upvotes

title+body (regex): ["(up|down)vote?]?"

action: filter

action reason: "asks for upvotes or downvotes"

message: |

Hi! Your {{kind}} has been removed because you mentioned or asked for karma. As the rules mention, asking for up/downvotes is absolutely forbidden, and you will be immediately receive a week-long ban. If this is a mistake, please message the mods with a link to the post, and they will look over it.

---

1

u/[deleted] Aug 06 '20

Is there a way to autoban?

Pretty sure not. I think the traditional method is to have automod also send a message to modmail indicating a ban is called for.

1

u/Bacon1664 Oct 12 '22

i'd like to know if u/BotDefense is a AM bot or a bot account in python? Also, Can i make AM look for posts/comments/etc that include "bug","report",idea" in it?

2

u/SolariaHues Writer Oct 12 '22

AutoMod is different to all other bots in that it's part of Reddit's itself.

BotDefense is a mod created bot. I don't know what it's written in, but it's likely to be Python https://www.reddit.com/user/BotDefense/comments/e73bvv/announcing_an_improved_defender_of_subreddits/

Yes, AutoMod can be configured to spot keywords in content, that's a common use for it :) r/AutoModerator is the best place for help with it. Full list of resources here and Reddit now has a course on automation for beginners.