Automod system. Banned word detection by CTK, the automod is from me. Timeouts for 10 minutes upon 3 warns.
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const random = require('something-random-on-discord').ServerAssistant;
/* Check the message content */
const checker = await random.checkProfanity(context.params.event.content);
/* if it do not include swear word then exit the process */
if (!checker.profanity) return;
if (context.params.event.member.roles.includes(`${process.env.ADMINROLE}`)) return;
/* Delete Message */
await lib.discord.channels['@0.1.1'].messages.destroy({
message_id: context.params.event.id,
channel_id: context.params.event.channel_id,
});
let currentwarnings = await lib.utils.kv['@0.1.16'].get({
key: `${context.params.event.author.id}warnings`,
});
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${process.env.ADMINROLE}`,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: '',
description: `Reason: Message contains banned words.`,
color: 0xff0000,
author: {
name: `${context.params.event.author.username}'s message has been deleted.`,
},
footer: {
text: `The User now has ${currentwarnings} automoderator warning in the Server!`,
},
},
],
});
//checking warn triggers
if (currentwarnings === `null`) {
await lib.utils.kv['@0.1.16'].set({
key: `${context.params.event.author.id}warnings`,
value: `1`,
});
await lib.discord.users['@0.2.0'].dms.create({
recipient_id: `${context.params.event.author.id}`,
content: `You were warned in Map Creators. You currently have 1 warnings.\n> *Reason: Message contains banned words.*`,
});
return;
}
let n = parseInt(currentwarnings);
let ew = n + 1;
if (ew === 3) {
await lib.utils.kv['@0.1.16'].set({
key: `${context.params.event.author.id}warnings`,
value: `0`,
});
await lib.discord.guilds['@0.2.2'].members.timeout.update({
user_id: `${context.params.event.author.id}`,
guild_id: `${context.params.event.guild_id}`,
communication_disabled_until_seconds: 600,
reason: `3 AutoModerator Warnings`,
});
await lib.discord.users['@0.2.0'].dms.create({
recipient_id: context.params.event.author.id,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: '',
description: `Reason: Message contains banned words.`,
color: 0xff0000,
author: {
name: `${context.params.event.author.username}'s message has been deleted.`,
},
footer: {
text: `The User is now Muted for 10 minutes due to 3 warnings!`,
},
},
],
});
await lib.discord.users['@0.2.0'].dms.create({
recipient_id: `${context.params.event.author.id}`,
content: `You have been timed out for 10 minutes.\n> Reason: 3 AutoModerator Warnings.`,
});
} else {
await lib.utils.kv['@0.1.16'].set({
key: `${context.params.event.author.id}warnings`,
value: n + 1,
});
await lib.discord.users['@0.2.0'].dms.create({
recipient_id: `${context.params.event.author.id}`,
content: `You were warned in Map Creators.You currently have ${ew} warnings.\n> *Reason: Message contains banned words.*`,
});
}