This snippet scans all image attachments sent in your server to see if they contain NSFW, gore, weapons, alcohol, drugs, scam or offensive content. If it does, it will ping your staff members in your log channel. You can get your free API key at https://dashboard.sightengine.com/api-credentials
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const axios = require('axios');
if (context.params.event.attachments.length) {
const message = await lib.discord.channels['@0.2.0'].messages.retrieve({
message_id: `${context.params.event.id}`,
channel_id: `${context.params.event.channel_id}`,
});
let image_url = null;
// Try to find an uploaded image
if (message.attachments.length) {
const attachment = message.attachments[0];
if (attachment.content_type.startsWith('image/'))
image_url = attachment.url;
}
// Try to find an embeded image
else if (message.embeds.length) {
const embed = message.embeds[0];
if (embed.url) image_url = embed.url;
}
let checkimage = await lib.http.request['@1.1.6'].get({
url: `https://api.sightengine.com/1.0/check.json`,
queryParams: {
models: `nudity,wad,offensive,scam,text-content,gore`, // This checks against nudity, wad, scam offensive and gore pictures. If you want to check more categories, visit https://sightengine.com/docs/getstarted to see how to add those categories.
url: `${image_url}`,
api_user: `${process.env.api_user}`,
api_secret: `${process.env.api_secret}`,
},
});
console.log(checkimage);
let cad = checkimage.data;
if (
cad.nudity.raw > 0.25 ||
cad.gore.prob > 0.25 ||
cad.weapon > 0.25 ||
cad.alcohol > 0.25 ||
cad.drugs > 0.25 ||
cad.scam.prob > 0.25 ||
cad.offensive.prob > 0.25
) {
try {
await lib.discord.channels['@0.3.1'].messages.destroy({
message_id: `${message.id}`, // required
channel_id: `${message.channel_id}`, // required
});
} catch (error) {
console.error(`Could not delete the message, error detected: ${error}`);
}
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: `${log_channel}`,
content: `An attachment sent by <@!${message.author.id}> was deleted in <#${message.channel_id}> <@&${staff_role}>`,
embed: {
image: {
url: `${image_url}`,
},
color: 0xff0000,
},
});
}
}