Tagscript

EmbedParser

TagScript


Class: EmbedParser

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

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}
{embed(image): https://random-d.uk/api/randomimg}
{embed(footer): Posted by the mods|https://random-d.uk/api/randomimg}

The result is an APIEmbed, the shape Discord's API takes and the shape discord.js EmbedBuilder.from reads.

import { EmbedBuilder } from 'discord.js';
import { EmbedParser } from '@tagscript/plugin-discord';
import { Interpreter } from 'tagscript';

const ts = new Interpreter(new EmbedParser());
const result = await ts.run('{embed: { "title": "Hello!", "description": "This is a test embed." }}');

const embed = EmbedBuilder.from(result.actions.embed);

Remarks

A template author picks both the property names and the values, so the result is typed APIEmbed for convenience and is not validated. Check it before you send it.

Extends

  • BaseParser

Implements

  • IParser

Constructors

Constructor

new EmbedParser(): EmbedParser

Defined in: tagscript-plugin-discord/src/lib/Parsers/Embed.ts:62

Returns

EmbedParser

Overrides

BaseParser.constructor

Properties

acceptedNames

protected acceptedNames: string[]

Defined in: tagscript/dist/index.d.mts:393

Inherited from

BaseParser.acceptedNames


requiredParameter

protected requiredParameter: boolean

Defined in: tagscript/dist/index.d.mts:394

Inherited from

BaseParser.requiredParameter


requiredPayload

protected requiredPayload: boolean

Defined in: tagscript/dist/index.d.mts:395

Inherited from

BaseParser.requiredPayload

Methods

parse()

parse(ctx): Promise<string>

Defined in: tagscript-plugin-discord/src/lib/Parsers/Embed.ts:66

Parses the given tag.

Parameters

ctx

Context

The context of the tag.

Returns

Promise<string>

Implementation of

IParser.parse


parseEmbedJSON()

protected parseEmbedJSON(payload): Awaitable<APIEmbed>

Defined in: tagscript-plugin-discord/src/lib/Parsers/Embed.ts:116

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>


toJSON()

toJSON(): object

Defined in: tagscript/dist/index.d.mts:398

Returns

object

acceptedNames

acceptedNames: string[]

requiredParameter

requiredParameter: boolean

requiredPayload

requiredPayload: boolean

Inherited from

BaseParser.toJSON


willAccept()

willAccept(ctx): boolean

Defined in: tagscript/dist/index.d.mts:397

Parameters

ctx

Context

Returns

boolean

Implementation of

IParser.willAccept

Inherited from

BaseParser.willAccept

On this page