Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

SwitchbladeBot/discord-embed-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

discord-embed-validator

joi schema for validating Discord Embed Objects.

The official documentation for the Embed Object can be found here, and its limits here.

Install

npm install discord-embed-validator

Usage examples

Valid Embed

const validator = require('discord-embed-validator')

const embed = {
  title: 'This is my valid embed!',
  fields: [
    {
      name: 'It has a field',
      value: 'And the field has a value!'
    }
  ]
}

validator.validate(embed)
// { value: { title: 'This is my valid embed!', fields: [ [Object] ] } }

Invalid Embed

const validator = require('discord-embed-validator')

const invalidEmbed = {
  title: 'This one is invalid',
  fields: [
    {
      'title': 'Because this field uses "title" instead of "name", and is missing its value!'
    }
  ]
}

validator.validate(invalidEmbed)
/*
{
  value: { title: 'This one is invalid', fields: [ [Object] ] },
  error: [Error [ValidationError]: "fields[0].name" is required] {
    _original: { title: 'This one is invalid', fields: [Array] },
    details: [ [Object] ]
  }
}
*/