A simple npm package written in Rust to template discord.js embeds.
Uses the APIEmbed structure as a basis for the serialization model (some optional properties such as timestamp are ommitted).
First, import the package (assuming you have installed it with npm
already):
// src/index.mjs
import * as QuickEmbed from "djs-quickembed";
Next, you must create a TOML string with the embed template. This can be done by many means, but the best way of doing it is creating a simple TOML file and reading it:
# src/templates/hello.toml
title = "Hello, {% name %}!"
description = "This is a description."
[[field]]
name = "Field 1"
value = "This is a field."
// src/index.mjs
const fs = require("node:fs");
const templateStr = fs.readFileSync("./src/templates/hello.toml", "utf-8");
And now you can use QuickEmbed.parse_template
to initialize a template:
// src/index.mjs
const helloTemplate = QuickEmbed.parse_template(templateStr);
Finally, you render your embed with QuickEmbed.render
and send it:
// src/index.mjs
let helloEmbed = QuickEmbed.render(helloTemplate, { name: "World" });
channel.send({ embeds: [helloEmbed] });
This package is licensed under the MIT license.