Najova

DocsExtensionsdiscord.najova

discord.najova/moderation0.0.2

Official Najova Package

Warnings, timeouts and a log channel: /warn, /warnings, /timeout and /clearwarnings for moderators.

moderation: warnings, timeouts and a log

Needs discord.najova 0.0.7 or newer.

Switch it on for your project on the Packages page in Najova IDE (Home > Packages). Set the log channel, the automatic timeout and the slash commands (/warn, /warnings, /timeout, /clearwarnings) there. Then $use[discord] alone gives:

$use[discord]
$prefix[strike]
  $reply[That is warning $warnMember[$message[1];spam]]
$endprefix
$start[$env[DISCORD_TOKEN]]
FunctionDoes
$warnMember[person;reason]warns a member, logs it, gives their number of warnings (a timeout follows at the Packages page setting)
$warningsOf[person]their warnings: a list of tables with reason, by and at
$clearWarnings[person]clears them and logs it
$timeoutMember[person;minutes;reason]times a member out (0 minutes ends it) and logs it
$modLog[text]a line in the log channel

The older way ($call)

Bots made before 0.0.7 keep working:

Slash commands for moderators, with a log channel. Add it to a bot:

$use[discord]
$use[discord/moderation]
$call[moderation.setup;$table[log;"123456789012345678";timeoutAt;3;timeoutMinutes;60]]
$call[moderation.commands]
$call[discord.start;$env[DISCORD_TOKEN]]
CommandWhat it does
/warn member [reason]Gives a warning; at timeoutAt warnings the member is timed out for timeoutMinutes
/warnings memberLists a member's warnings (only the moderator sees it)
/timeout member minutes [reason]Times a member out (they cannot write or talk); 0 minutes ends it
/clearwarnings memberClears a member's warnings

Only people who may time members out (the Moderate Members permission) can use them; others get "Only moderators can use this." Everything is written to the log channel when there is one.

Calls

CallWhat it does
$call[moderation.setup;$table[...]]log (a channel id, "" = no log), timeoutAt (warnings before an automatic timeout, 0 = never), timeoutMinutes, permission (the Discord permission the commands need, ModerateMembers unless you change it)
$call[moderation.commands]Adds the four slash commands
$call[moderation.warn;where;person;reason;by]A warning from your own script (a word filter, say); gives the number of warnings
$call[moderation.warnings;where;person]The member's warnings: a list of tables with reason, by and at (seconds since 1970)
$call[moderation.timeout;where;person;minutes;reason;by]A timeout from a script
$call[moderation.clear;where;person;by]Clears the warnings
$call[moderation.log;text]A line in the log channel

Warnings are kept per member in the member variable warnings (discord-variables.json). The bot needs the Moderate Members permission, and its role above the people it times out.

Needs discord.najova 0.0.2 or newer.

Functions

moderation.setup

$call[moderation.setup;$table[log;"<channel id>";timeoutAt;3;timeoutMinutes;60]]

Where to log (the log channel id) and an automatic timeout after that many warnings (timeoutAt, 0 = never) for timeoutMinutes.

moderation.log

$call[moderation.log;text]

A line in the log channel (when there is one).

moderation.warnings

$call[moderation.warnings;where;person]

A person's warnings: a list of tables with reason, by and at.

moderation.warn

$call[moderation.warn;where;person;reason;by]

Warns a person, logs it and gives the number of warnings they have; a timeout follows at the timeoutAt setting.

moderation.clear

$call[moderation.clear;where;person;by]

Clears a person's warnings and logs it.

moderation.timeout

$call[moderation.timeout;where;person;minutes;reason;by]

Times a person out for some minutes and logs it (0 minutes ends a timeout).

moderation.commands

$call[moderation.commands]

Adds /warn, /warnings, /timeout and /clearwarnings, only for people who may time members out.

moderation.warnMember

$warnMember[person;reason]

Warns a member (by id) in the server of the command or event, logs it and gives their number of warnings.

moderation.warningsOf

$warningsOf[person]

A member's warnings: a list of tables with reason, by and at.

moderation.clearWarnings

$clearWarnings[person]

Clears a member's warnings and logs it.

moderation.timeoutMember

$timeoutMember[person;minutes;reason]

Times a member out for some minutes and logs it (0 minutes ends a timeout).

moderation.modLog

$modLog[text]

A line in the log channel (when one is set).