This snippet will detect banned words which you can set on line 5. If you send a banned word it will delete it, create a webhook, and then re-send your message with a spoiler.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let message = context.params.event.content;
let words = ['word1', 'word2', 'word3']; // <-- You can add more than 3 if you would like
let regEx = new RegExp(words.join('|'), 'gi');
if (message.match(regEx)) {
await lib.discord.channels['@0.3.2'].messages.destroy({
message_id: `${context.params.event.id}`,
channel_id: `${context.params.event.channel_id}`,
});
console.log(`DELETED MESSAGE`);
let avatar =
`https://cdn.discordapp.com/avatars/` +
context.params.event.author.id +
`/` +
context.params.event.author.avatar +
`.png?size=1024`;
console.log(`MADE URL`);
avatar = await lib.http.request['@1.1.6']({
method: 'GET',
url: `${avatar}`,
});
console.log(`BUFFERED AVATAR`);
let webhook = await lib.discord.webhooks['@0.1.0'].create({
channel_id: `${context.params.event.channel_id}`,
name: `${context.params.event.author.username}`,
avatar: avatar.body,
});
console.log(`WEBHOOK CREATED`);
//Remove and replace the word
filtered = '||' + message + '||';
console.log(`MESSAGE FILTERED`);
await lib.discord.webhooks['@0.1.0'].execute({
webhook_id: `${webhook.id}`,
webhook_token: `${webhook.token}`,
content: filtered,
});
console.log(`MESSAGE SENT`);
}
//Code detects a banned word, deleted it, then creates a webhook and re-sends the message with a spoiler