This snippets allow the bot to remove messages and auto warn members who use any words from the ban list. Add the words you want to ban on line 13.
module.exports = async (event, context) => {
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const userID = `${context.params.event.author.id}`;
const user = context.params.event.author;
const imageUrl = user.avatar
? `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png?size=512`
: 'https://polybit-apps.s3.amazonaws.com/stdlib/users/discord/profile/image.png?1621007833204';
const username = `${context.params.event.author.username}`;
const BANNED_WORDS = [`1st banned word`,'2nd banned word',]; // Add banned words
//if you want to add more words just add `` after , and add the word
const regEx = new RegExp(BANNED_WORDS.join('|'), 'gi');
let messageContent = event.content;
if (messageContent.match(regEx)) {
await lib.discord.channels['@0.3.0'].messages.destroy({
message_id: event.id,
channel_id: event.channel_id,
}),
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: 'WARNING!!',
description: `Warning you are using wrong language <@${userID}>`,//message send in channel where bad word is used
color: 0xffffff,
},
],
});
await lib.discord.channels['@0.0.3'].messages.create({
channel_id: `channel id`, // Log channel id
content: '', // Message outside embed
tts: false,
embed: {
type: 'rich',
author: {
name: `Bad Word Usage`,
icon_url: `${imageUrl}`, // Authors Icon aka the person who has used banned words
},
title: '', // Title of embed
description: `${username} has said a banned word`,
color: 0xffffff, //embed line color
fields: [
{
name: 'User',
value: `<@!${userID}> | \`${userID}\` | <#${context.params.event.channel_id}>`,// shows user ping, id and the channel in which bad word is used.
},
{
name: 'Filtered Message',
value: `*${messageContent}*`,//the message which user used
},
],
timestamp: new Date(),//on what time it used
footer: {
text: '',
},
},
});
}
};
//if you get error ping @DeathManager in autocode discord server.