|
1 | 1 | --- |
2 | 2 | title: EmbedParser |
3 | 3 | --- |
| 4 | + |
| 5 | +import { Callout } from 'fumadocs-ui/components/callout'; |
| 6 | +import { Tabs } from 'fumadocs-ui/components/tabs'; |
| 7 | + |
| 8 | +The embed tag creates Discord embeds that can be sent along with messages. |
| 9 | +There are two ways to use the embed tag: either by using properly formatted embed JSON or by manually inputting the accepted embed properties. |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +<Tabs items={['ESM', 'CommonJs']}> |
| 14 | + ```ts showLineNumbers tab="ESM" |
| 15 | + import { Interpreter } from 'tagscript'; |
| 16 | + import { EmbedParser } from '@tagscript/plugin-discord'; |
| 17 | + const ts = new Interpreter(new EmbedParser()); |
| 18 | + ``` |
| 19 | + ```js showLineNumbers tab="CommonJs" |
| 20 | + const { Interpreter } = require('tagscript'); |
| 21 | + const { EmbedParser } = require('@tagscript/plugin-discord'); |
| 22 | + const ts = new Interpreter(new EmbedParser()); |
| 23 | + ``` |
| 24 | +</Tabs> |
| 25 | + |
| 26 | +## API |
| 27 | + |
| 28 | +Check [EmbedParser](../../../typedoc-api/@tagscript/plugin-discord/classes/EmbedParser) for the API documentation. |
| 29 | + |
| 30 | +## For End Users |
| 31 | + |
| 32 | +<Callout type="info" emoji={null}> |
| 33 | +### Syntax |
| 34 | + |
| 35 | +**Using JSON:** |
| 36 | +```yaml |
| 37 | +{embed:json} |
| 38 | +``` |
| 39 | + |
| 40 | +**Using properties:** |
| 41 | +```yaml |
| 42 | +{embed(property):value} |
| 43 | +``` |
| 44 | + |
| 45 | +### Examples |
| 46 | + |
| 47 | +**JSON Format:** |
| 48 | +```yaml |
| 49 | +{embed:{"title": "Hello!", "description": "This is a test embed."}} |
| 50 | +``` |
| 51 | + |
| 52 | +```yaml |
| 53 | +{embed:{ |
| 54 | + "title": "Here's a random duck!", |
| 55 | + "image": {"url": "https://random-d.uk/api/randomimg"}, |
| 56 | + "color": 15194415 |
| 57 | +}} |
| 58 | +``` |
| 59 | + |
| 60 | +**Property Format:** |
| 61 | +```yaml |
| 62 | +{embed(color):0x37b2cb} |
| 63 | +{embed(title):Rules} |
| 64 | +{embed(description):Follow these rules to ensure a good experience in our server!} |
| 65 | +{embed(field):Rule 1|Respect everyone you speak to.|false} |
| 66 | +``` |
| 67 | + |
| 68 | +```yaml |
| 69 | +{embed(author):Author Name} |
| 70 | +{embed(thumbnail):https://example.com/image.png} |
| 71 | +{embed(footer):Footer text} |
| 72 | +{embed(timestamp):true} |
| 73 | +``` |
| 74 | + |
| 75 | +### Available Properties |
| 76 | + |
| 77 | +- `title` - The embed title |
| 78 | +- `description` - The embed description |
| 79 | +- `color` - The embed color (hex code or number) |
| 80 | +- `author` - The embed author name |
| 81 | +- `thumbnail` - URL for the thumbnail image |
| 82 | +- `image` - URL for the main image |
| 83 | +- `footer` - The footer text |
| 84 | +- `timestamp` - Set to `true` to add current timestamp |
| 85 | +- `field` - Add a field with format: `name|value|inline` |
| 86 | + |
| 87 | +### Field Format |
| 88 | + |
| 89 | +Fields use the format: `{embed(field):name|value|inline}` |
| 90 | +- `name` - The field name |
| 91 | +- `value` - The field value |
| 92 | +- `inline` - `true` or `false` for inline display |
| 93 | + |
| 94 | +### Notes |
| 95 | + |
| 96 | +- Multiple embed tags in the same TagScript will merge properties |
| 97 | +- Color values can be hex codes (0x37b2cb) or decimal numbers |
| 98 | +- JSON format allows for more complex embed structures |
| 99 | +- Developers need to construct the embed builder with the parser output |
| 100 | + |
| 101 | +</Callout> |
| 102 | + |
| 103 | +## Developer Example |
| 104 | + |
| 105 | +```ts showLineNumbers |
| 106 | +import { Interpreter } from 'tagscript'; |
| 107 | +import { EmbedParser } from '@tagscript/plugin-discord'; |
| 108 | +import { EmbedBuilder } from 'discord.js'; |
| 109 | + |
| 110 | +const ts = new Interpreter(new EmbedParser()); |
| 111 | +const result = await ts.run('{embed:{"title": "Hello!", "description": "This is a test embed."}}'); |
| 112 | + |
| 113 | +// You might need to modify the embed object before passing to EmbedBuilder |
| 114 | +const embed = new EmbedBuilder(result.actions.embed); |
| 115 | +``` |
0 commit comments