View on GitHub


Generate captcha images for use with bots on chat platforms

License NPM version NPM downloads FOSSA Status Dependencies PayPal Portfolio

Captcha Generator

Captcha Generator is a Node library for quickly and easily generating captcha images that can be used through an authorized bot to verify human users on a chat platform such as Slack or Discord.


Use the package manager npm to install Captcha Generator

npm i @haileybot/captcha-generator



// Import the module
const Captcha = require("@haileybot/captcha-generator");

// Create a new Captcha object
//  - Optional argument to specify image height (250 to 400px, default 250)
//    - Image width is 400px
//  - Returned object will contain "PNGStream" and "value"
//    - "PNGStream" is a stream object for the image file in PNG format
//    - "JPEGStream" is a stream object for the image file in JPEG format
//    - "value" is the 6 character code the image contains
let captcha = new Captcha();

Save to file example:

const path = require("path"),
  fs = require("fs"),
  Captcha = require("@haileybot/captcha-generator");

let captcha = new Captcha();
captcha.PNGStream.pipe(fs.createWriteStream(path.join(__dirname, `${captcha.value}.png`)));
captcha.JPEGStream.pipe(fs.createWriteStream(path.join(__dirname, `${captcha.value}.jpeg`)));

Discord Example:

This example assumes you already have the core framework of a Discord Bot set up

const Captcha = require("@haileybot/captcha-generator");

// Use this function for blocking certain commands or features from automated self-bots
function verifyHuman(msg) {
  let captcha = new Captcha();
    "**Enter the text shown in the image below:**",
    new Discord.MessageAttachment(captcha.JPEGStream, "captcha.jpeg")
  let collector = => ===;
  collector.on("collect", m => {
    if (m.content.toUpperCase() === captcha.value)"Verified Successfully!");
    else"Failed Verification!");


This project is licensed under GPL-3.0

FOSSA Status