TypeDoc API
Plugins
Plugin Discord
Classes
Embedparser

Class: EmbedParser

An embed tag will send an embed in the tag response. There are two ways to use the embed tag, either by using properly formatted embed JSON or manually inputting the accepted embed properties.

Embed can be used either by using a json string or by using the embed properties.

Example

Using JSON

{embed: json}

Example

{embed: { "title": "Hello!", "description": "This is a test embed." } }
{embed: {
    "title": "Here's a random duck!",
    "image": { "url": "https://random-d.uk/api/randomimg" },
    "color": 15194415
} }

Example

Using properties

{embed(property):value}

Example

{embed(color): 0x37b2cb}
{embed(title): Rules}
{embed(description): Follow these rules to ensure a good experience in our server!}
{embed(field): Rule 1|Respect everyone you speak to.|false}

Developers need to construct the embed builder themselves with the output of the tag.

Example

const { Interpreter } = require("tagscript")
const { EmbedParser } = require("tagscript-plugin-discord")
 
const ts = new Interpreter(new EmbedParser())
const result = await ts.run('{embed: { "title": "Hello!", "description": "This is a test embed." }}')
 
// You might need to change the embed object before passing to `EmbedBuilder`. Changes such as change thumbnail and image value from string to object.
const embed = new EmbedBuilder(response.actions.embed);

Remarks

The return type depends on user's input. So it might not be EmbedData | APIEmbed. So use a typeguard to check.

Hierarchy

Implements

Constructors

constructor

new EmbedParser()

Overrides

BaseParser.constructor

Properties

acceptedNames

Protected acceptedNames: string[]

Inherited from

BaseParser.acceptedNames


requiredParameter

Protected requiredParameter: boolean

Inherited from

BaseParser.requiredParameter


requiredPayload

Protected requiredPayload: boolean

Inherited from

BaseParser.requiredPayload

Methods

parse

parse(ctx): Promise (opens in a new tab)<string>

Parses the given tag.

Parameters

NameTypeDescription
ctxContextThe context of the tag.

Returns

Promise (opens in a new tab)<string>

Implementation of

IParser.parse


parseEmbedJSON

Protected parseEmbedJSON(payload): Awaitable<APIEmbed (opens in a new tab) | EmbedData (opens in a new tab)>

This method is protected so that anyone can extend the embed json parser to allow urls

Parameters

NameTypeDescription
payloadstringThe payload to parse

Returns

Awaitable<APIEmbed (opens in a new tab) | EmbedData (opens in a new tab)>


returnEmbed

Private returnEmbed(ctx, data): string

Parameters

NameType
ctxContext
dataAPIEmbed (opens in a new tab) | EmbedData (opens in a new tab)

Returns

string


willAccept

willAccept(ctx): boolean

Whether the parser can handle the given tag.

Parameters

NameTypeDescription
ctxContextThe context of the tag.

Returns

boolean

Implementation of

IParser.willAccept

Inherited from

BaseParser.willAccept