Writing policy sets
Tips
Say what to flag. A goal like "We want a respectful community" gives the check nothing to act on. "No insults or personal attacks directed at another person" does.
Number your rules. It makes clear where one rule ends and the next begins.
await policies.save('comments', `
1) No threats of violence.
2) No slurs or hate speech targeting a protected group.
3) No links to file-sharing sites.
`);
Keep an exception in the same rule. "No weapons, unless holstered on a uniformed guard" works. Splitting it into "No weapons" and "Weapons are allowed on guards" can be refused as a contradiction.
Write about what can be seen in the content. A check can't know someone's age, whether they consented, or who owns a photo. "No photos of a person in a bathroom or bedroom" can be checked; "No photos posted without consent" can't.
Use one set per surface. For example public-feed and minor-account, and
pick the set when you check:
await client.checkText(message, user.isMinor ? 'minor-account' : 'public-feed');
Try it first. The dashboard's Playground runs a check against any set, so you can adjust the wording before you ship.
Managing sets
const policies = new Policies(creds);
await policies.save('comments', RULES); // create or overwrite
await policies.save('comments', RULES, { ifNotExists: true }); // fail if it exists
await policies.get('comments'); // { name, text, createdAt, updatedAt }
await policies.list(); // every set in the project
await policies.remove('comments');
- An edit takes effect once its save finishes.
- After a set is deleted, checks that name it fail with an error.
- You can also manage sets in the dashboard's Policy manager.
When a save is refused
save() throws an Error with a message you can show as it is. The common
reasons:
- Two rules contradict each other.
- Nothing in the text is a rule about content.
- More than 40 rules, or the rules are too complex. Split the set.
- The text is over 20,000 characters, or the name over 100.
See Errors for the full list.