Nexo: AI Combats Internet Toxicity

Google's Perspective API, Replit's Hosting & Storage Platform, and Discord.py. The perfect ingredients for a new-age moderation bot.

Nexo: AI Combats Internet Toxicity
Photo by Henry Hustava / Unsplash

Hey, I'm Dhanush. In 2021, I watched a youtube video which inspired me to work on my first discord bot!

The video discussed Google's Perspective API. The Perspective API allows one to retrieve statistics about a piece of text, primarily, how toxic or hurtful a text is.

This is one use-case for sentiment analysis. Here's an example of what the API returns for the text "Hello World":

{
  "attributeScores": {
    "TOXICITY": {
      "spanScores": [
        {
          "begin": 0,
          "end": 11,
          "score": {
            "value": 0.020842785,
            "type": "PROBABILITY"
          }
        }
      ],
      "summaryScore": {
        "value": 0.020842785,
        "type": "PROBABILITY"
      }
    }
  },
  "languages": [
    "en"
  ],
  "detectedLanguages": [
    "en",
    "fil"
  ]
}

The API can return a lot more information, including more granular data.


After requesting access to the API, inspired by the video, I wanted to make a Discord Moderation Bot which kept chats safe.

For this, I used the popular discord.py framework, developed by @Rapptz. For someone straight out of "Python for Kids", this was a huge step up. Discord.py was a framework that made use of intermediate and advanced Python concepts - think asynchronous code and decorators. A few years later, I'd know Python like the back of my hand, but at this stage - it was daunting.

I used to use replit with the GitHub Student Developer pack. I wrote my code on their platform, leveraging their Key-Value Database. I preferred Replit's database because it could be accessed like a persistent dictionary 😁.

db[key] = value

Was the syntax, that's it! Nowadays, I prefer PostgreSQL, but I definitely understand the appeal that such simple syntax would hold to a beginner.


Replit's Platform for Persistent Storage and Hosting, Discord.py as a bot framework, and the Perspective API. After combining these ingredients, I ended up with Nexo, my first ever discord bot. This gave me the confidence to accept my first freelance gig!