Last active
March 6, 2022 13:46
-
-
Save manhbi18112005/99c4fea9424968f8c37c4492fce62f8c to your computer and use it in GitHub Desktop.
Moderate messages in your servers automatically using Artificial Intelligence. The code below was made to put in index.js, you can modify it to put in an event file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
const GOOGLE_API_KEY = "CóCáiLồnĐịtConBàMày" | |
const snekfetch = require('snekfetch'); | |
client.on("message", async message => { | |
if (message.author.bot) return; // return if message was sent from bot | |
const emojiId = message.content.replace(/<a?:(.*?):+/g, ''); | |
let imageUrl = `https://cdn.discordapp.com/emojis/${emojiId}`; | |
if(message.content === imageUrl) return; // return if message only contains emojis | |
const text = message.content; | |
try { | |
const { body } = await snekfetch | |
.post('https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze') | |
.query({ key: GOOGLE_API_KEY}) | |
.send({ | |
comment: { text }, | |
languages: ['en'], | |
requestedAttributes: { TOXICITY: {} } | |
}); | |
const toxicity = Math.round(body.attributeScores.TOXICITY.summaryScore.value * 100); | |
if (toxicity > 85) { | |
message.delete(); | |
message.channel.send(`Hey ${message.author}, please do not use toxic words here!`) | |
} | |
} catch (err) { | |
return message.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); | |
} | |
}) |
it works, thank you
Thank you very much for the feedback, wouldn't you mind leaving a star? :)
I dont know much about API keys, but you probably dont want to leave that API key as valid.
I dont know much about API keys, but you probably dont want to leave that API key as valid.
I can't share that API key, so I decided to insert it with a quote from our nations. :>
You can register your own Google API keys by searching Google. It's will be very helpful. 😍
Thank you for reading this. :3
Ah cool. I don't need the API key, just didnt want you to end up with a big bill for someone using it crypto mining.
Have a good one.
:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it works, thank you