Faizo

Writing · Discord · Components V2 · Front end

Measuring how Discord renders a message instead of guessing

Keeping a Discord message preview faithful by measuring Discord's own client: the workflow, media gallery layout rules, failure states and markdown quirks.

DWEEB shows a live preview of the message you're building, and the whole product depends on that preview being right. If it shows a two-image gallery at one height and Discord shows it at another, people stop trusting it, and a builder you can't trust is just a JSON editor with extra steps.

Early on I styled the preview by eye from screenshots. It was always slightly off, and I couldn't say by how much. So I switched to measuring: send the same message to Discord, then read the numbers out of Discord's own web client. This article describes that workflow and the rules it produced, which may save you some time if you build anything that renders Discord messages.

The workflow

  1. Build the message in the editor and export its exact JSON payload.
  2. Post it to a test webhook in a private server. For Components V2 messages, webhook execution needs ?with_components=true and the message flag IS_COMPONENTS_V2 (1 << 15), or the components are refused.
  3. Open the message in Discord's web client and read the rendered DOM with the developer tools: element sizes, getComputedStyle values, the CSS custom properties the theme defines.
  4. Write the measured values into the preview as named tokens, with a note saying where they came from, so nobody "fixes" them by eye later.

One practical snag: Discord's current client expresses many colors in oklab(), which is hard to compare with hex values. The simplest reliable conversion is to let the browser do it, by painting the color into a one-pixel canvas and reading the pixel back:

function measuredColor(cssColor) {
  const ctx = document.createElement("canvas").getContext("2d", { willReadFrequently: true });
  ctx.clearRect(0, 0, 1, 1);
  ctx.fillStyle = cssColor;          // e.g. "oklab(0.27 0.002 -0.008)"
  ctx.fillRect(0, 0, 1, 1);
  const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
  const hex = [r, g, b].map((v) => v.toString(16).padStart(2, "0")).join("");
  return { hex: "#" + hex, alpha: +(a / 255).toFixed(3) };
}

Measure the right surface

My first audit got the background wrong in a way that's easy to repeat. In Discord's 2026 dark theme the app frame behind the chat is a near-black (#121214), but messages render on the chat panel, which is #1a1a1e. I sampled the frame, and the preview read far too dark beside the editor. Always find the element the message is actually inside before sampling.

A related rule: keep colors that are meant to work together within one theme. My preview canvas deliberately uses classic dark mode's chat background (#313338), because the newer, darker surfaces looked too heavy next to the editor. Containers then have to use classic dark's container color too (#2b2d31). Mixing the newer theme's container color onto the classic background produced a container that looked like a hole in the page. In the newer theme, containers are lighter than the chat. In the classic theme, they're darker. A pair from one theme always looks right. A mixed pair doesn't.

The Components V2 media gallery holds up to ten images, and Discord lays them out differently depending on the count. These are the rules I measured. They're the same at the top level and inside a container. A container just narrows the column, to 566 px in my measurements.

ImagesLayout
1The image at its natural aspect ratio, capped at 600 px wide and 350 px tall.
2Two columns at a fixed 280 px height. The source aspect ratio is ignored.
3A hero on the left and two stacked on the right, in a 2fr / 1fr split, with the whole block at 12:7.
4A 2×2 grid whose cells take the source image's aspect ratio (3:2 if it can't be read).
5A 280 px-high pair, as for two, above a row of three squares.
6 and 9All squares, three per row.
7 and 10A full-width hero at the source aspect ratio (no height cap) above rows of squares.

The two-image case surprised me most. I had assumed Discord would respect the images' shapes. It doesn't: two portrait photos and two panoramas get the same 280 px-high strip, cropped.

A spoilered container also behaves as a unit: the whole card is blurred heavily (I measured blur(44px)), its accent stripe is hidden, and a "SPOILER" pill sits on top.

Failure states are part of the design

A preview also has to show what happens when things go wrong, because that's what the recipient will see. Measured:

  • An image that fails to load keeps its cell's geometry and shows a centered 32 px broken-image glyph on an almost transparent fill. A lone image becomes a 350×350 box and a section thumbnail an 85×85 one.
  • A custom emoji Discord can't resolve renders as plain :name: text, not as a broken image.
  • A long button label grows the button, and the row wraps. A long select-menu placeholder is truncated with an ellipsis.

Markdown quirks worth knowing

Discord's markdown isn't CommonMark, and several of its rules differ in ways you only find by testing. Every one of these is checked against real messages and pinned in a test file:

  • *italic* needs a non-space character right after the opening *, while _italic_ needs word boundaries on both sides.
  • An auto-detected link drops trailing punctuation: . , : ; " ' ) ].
  • Inline styles can continue across line breaks.
  • Consecutive ordered-list items directly after a bullet list are merged into that list.
  • Components V2 text displays never render "jumbo" emoji, even when a line contains only emoji.
  • Timestamps have nine styles, not seven: <t:1700000000:s> and <t:1700000000:S> (short date with short or medium time) joined the older t T d D f F R. A preview that only knows seven shows the newer two as raw text.

What I chose not to match

Some differences are deliberate and written down as such: no syntax highlighting inside code blocks, the device's native emoji instead of Discord's Twemoji artwork (the Discord Activity version of the app can't load third-party CDNs), and a fallback font when Discord's own isn't available. Writing the accepted gaps down matters as much as the measurements. Otherwise the next audit "fixes" them and breaks something else.

Takeaway

If a UI has to match another product, measure the other product. A real webhook, a test server and getComputedStyle give you numbers you can defend, and a short note next to each value ("measured off the live client, dark theme, this surface") stops it drifting back towards someone's guess.