This bot can be used to moderate your discord server with the help of open-ai! It checks all messages and if the message is not appropriate, it deletes it and gives the member a timeout (optional). If you want the bot to give timeout, set the env key name 'timeout' to true!
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
try {
let result = await lib.openai.playground['@0.0.4'].moderations.create({
model: `text-moderation-latest`,
input: [context.params.event.content],
});
if (result.results[0].flagged) {
await lib.discord.channels['@0.3.4'].messages.destroy({
message_id: context.params.event.id,
channel_id: context.params.event.channel_id,
});
await lib.discord.channels['@0.3.4'].messages.create({
channel_id: context.params.event.channel_id,
content: `**<@${context.params.event.author.id}>; Please don't use this kind of language!**`,
});
await lib.discord.channels['@0.3.4'].messages.create({
channel_id: process.env.log_channel,
content: ``,
embeds: [
{
title: `Member Warned`,
description: `<@${context.params.event.author.id}>; has been warned as they said:\n\`${context.params.event.content}\``,
color: 0x00ffff,
author: {
name: context.params.event.author.username + '#' + context.params.event.author.discriminator,
icon_url: `https://cdn.discordapp.com/avatars/${context.params.event.author.id}/${context.params.event.author.avatar}.png`,
},
},
],
});
if (process.env.timeout == true) {
await lib.discord.guilds['@0.2.4'].members.timeout.update({
user_id: context.params.event.author.id,
guild_id: context.params.event.guild_id,
communication_disabled_until_seconds: process.env.time,
reason: `Inappropriate behaviour.`,
});
await lib.discord.users['@0.2.1'].dms.create({
recipient_id: context.params.event.author.id,
content: `**<@${context.params.event.author.id}>; You have been timeout due to inappropriate behaviour!**`,
});
await lib.discord.channels['@0.3.4'].messages.create({
channel_id: process.env.log_channel,
content: ``,
embeds: [
{
title: `Member Timeout`,
description: `<@${context.params.event.author.id}>; has been timeout.`,
color: 0x00ffff,
author: {
name:
context.params.event.author.username + '#' + context.params.event.author.discriminator,
icon_url: `https://cdn.discordapp.com/avatars/${context.params.event.author.id}/${context.params.event.author.avatar}.png`,
},
},
],
});
}
}
} catch (e) {
console.log(e);
await lib.discord.channels['@0.3.4'].messages.create({
channel_id: process.env.log_channel,
content: ``,
embeds: [
{
title: `Error!`,
description: `\`\`\`js\n${e}\`\`\``,
color: 0x00ffff,
},
],
});
}