Functiondiscord-component-embedv1.1.1
fromPayload
Turns a component embed's JSON back into a tree. Use it to check JSON you wrote by hand or got from somewhere else.
Pass the result to toComponentEmbed or toComponentEmbedJson. They throw the same errors they
throw for a tree built with JSX.
Throws:
A
ComponentEmbedErrorwhen the JSON can't become a tree, like a component with a type no embed allows or a separator spacing other than 1 or 2. Itspathlists the JSON keys that lead to the problem.
fromPayload(payload: ComponentEmbedPayload): EmbedElement// parsed JSON goes straight in
const payload = JSON.parse(await readFile('embed.json', 'utf8'));
toComponentEmbed(fromPayload(payload));// annotate an object you write in code to get autocomplete and type errors
const card: ComponentEmbedPayload = {
component: { type: 17, components: [{ type: 10, content: '# Hello' }] }
};
toComponentEmbedScript(fromPayload(card));payload
payload: ComponentEmbedPayload