Class: EmbedParser
@tagscript/plugin-discord.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
-
BaseParser
↳
EmbedParser
Implements
IParser
Constructors
constructor
• new 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:380
requiredParameter
• Protected
requiredParameter: boolean
Inherited from
BaseParser.requiredParameter
Defined in
tagscript/dist/index.d.ts:381
requiredPayload
• Protected
requiredPayload: boolean
Inherited from
BaseParser.requiredPayload
Defined in
tagscript/dist/index.d.ts:382
Methods
parse
▸ parse(ctx
): Promise
(opens in a new tab)<string
>
Parameters
Name | Type |
---|---|
ctx | Context |
Returns
Promise
(opens in a new tab)<string
>
Implementation of
IParser.parse
Defined in
tagscript-plugin-discord/src/lib/Parsers/Embed.ts:61
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
Name | Type | Description |
---|---|---|
payload | string | The payload to parse |
Returns
Awaitable
<APIEmbed
(opens in a new tab) | EmbedData
(opens in a new tab)>
Defined in
tagscript-plugin-discord/src/lib/Parsers/Embed.ts:96
returnEmbed
▸ Private
returnEmbed(ctx
, data
): string
Parameters
Name | Type |
---|---|
ctx | Context |
data | APIEmbed (opens in a new tab) | EmbedData (opens in a new tab) |
Returns
string
Defined in
tagscript-plugin-discord/src/lib/Parsers/Embed.ts:102
willAccept
▸ willAccept(ctx
): boolean
Parameters
Name | Type |
---|---|
ctx | Context |
Returns
boolean
Implementation of
IParser.willAccept
Inherited from
BaseParser.willAccept
Defined in
tagscript/dist/index.d.ts:384