Tagscript

@tagscript/plugin-discordDocs


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.

Examples

Using JSON

{embed: json}
{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
} }

Using properties

{embed(property):value}
{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.

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.

Extends

  • BaseParser

Implements

  • IParser

Constructors

new EmbedParser()

new EmbedParser(): EmbedParser

Returns

EmbedParser

Overrides

BaseParser.constructor

Defined in

tagscript-plugin-discord/src/lib/Parsers/Embed.ts:57

Properties

acceptedNames

protected acceptedNames: string[]

Inherited from

BaseParser.acceptedNames

Defined in

tagscript/dist/index.d.ts:381


requiredParameter

protected requiredParameter: boolean

Inherited from

BaseParser.requiredParameter

Defined in

tagscript/dist/index.d.ts:382


requiredPayload

protected requiredPayload: boolean

Inherited from

BaseParser.requiredPayload

Defined in

tagscript/dist/index.d.ts:383

Methods

parse()

parse(ctx): Promise<string>

Parses the given tag.

Parameters

ctx: Context

The context of the tag.

Returns

Promise<string>

Implementation of

IParser.parse

Defined in

tagscript-plugin-discord/src/lib/Parsers/Embed.ts:61


parseEmbedJSON()

protected parseEmbedJSON(payload): Awaitable<APIEmbed | EmbedData>

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

Parameters

payload: string

The payload to parse

Returns

Awaitable<APIEmbed | EmbedData>

Defined in

tagscript-plugin-discord/src/lib/Parsers/Embed.ts:96


toJSON()

toJSON(): object

Returns

object

acceptedNames

acceptedNames: string[]

requiredParameter

requiredParameter: boolean

requiredPayload

requiredPayload: boolean

Inherited from

BaseParser.toJSON

Defined in

tagscript/dist/index.d.ts:386


willAccept()

willAccept(ctx): boolean

Parameters

ctx: Context

Returns

boolean

Implementation of

IParser.willAccept

Inherited from

BaseParser.willAccept

Defined in

tagscript/dist/index.d.ts:385

On this page