Skip to content
Functiondiscord-component-embedv1.1.1

toComponentEmbedScript

Returns the <script> tag Discord reads for a component embed as an HTML string. Use it where you write raw HTML into the page yourself.

Throws:

toComponentEmbedScript(root: EmbedElement): string
// src/routes/[...slug]/+page.server.ts in SvelteKit
export const load: PageServerLoad = async ({ params }) => {
    const page = await getGuidePage(params.slug);
    const title = h(TextDisplay, null, `# ${page.title}`);
    const preview = h(Container, { accentColor: 0xf8f6e8 }, title);

    // in +page.svelte, output it with {@html data.preview} inside <svelte:head>
    return { page, preview: toComponentEmbedScript(preview) };
};