discordjs/discord.js · error · Error

Cannot properly serialize section accessory component: ${com

Error message

Cannot properly serialize section accessory component: ${component.type}

What it means

resolveAccessoryComponent converts a section's accessory (the small component next to section text) into a builder. Only Button and Thumbnail accessories are supported; any other component type in the accessory slot hits the default branch and throws.

Source

Thrown at packages/builders/src/components/Components.ts:274

		case ButtonStyle.Link:
			return new LinkButtonBuilder(data);
		case ButtonStyle.Premium:
			return new PremiumButtonBuilder(data);
		default:
			// @ts-expect-error This case can still occur if we get a newer unsupported button style
			throw new Error(`Cannot properly serialize button with style: ${data.style}`);
	}
}

export function resolveAccessoryComponent(component: APISectionAccessoryComponent) {
	switch (component.type) {
		case ComponentType.Button:
			return createButtonBuilder(component);
		case ComponentType.Thumbnail:
			return new ThumbnailBuilder(component);
		default:
			// @ts-expect-error This case can still occur if we get a newer unsupported component type
			throw new Error(`Cannot properly serialize section accessory component: ${component.type}`);
	}
}

View on GitHub (pinned to a81ed8a306)

Solutions

  1. Update @discordjs/builders to the latest version in case new accessory types gained support.
  2. Ensure the accessory passed to the section is a button or thumbnail; restructure data otherwise.
  3. Guard resolution: check component.type against the supported set before calling resolveAccessoryComponent.
  4. If data comes from raw API payloads, strip or transform unsupported accessories first.

Example fix

// before
new SectionBuilder({ components: [...], accessory: mediaGalleryComponent }); // invalid accessory type
// after
new SectionBuilder({ components: [...], accessory: new ThumbnailBuilder(...) });
Defensive patterns

Strategy: type-guard

Validate before calling

const SUPPORTED_ACCESSORIES = new Set([ComponentType.Button, ComponentType.Thumbnail]);
if (!SUPPORTED_ACCESSORIES.has(component.type)) {
  throw new Error(`Accessory must be a button or thumbnail, got ${component.type}`);
}

Type guard

function isValidAccessory(c: { type: number }): c is APISectionAccessoryComponent {
  return c.type === ComponentType.Button || c.type === ComponentType.Thumbnail;
}

Try / catch

try {
  const accessory = resolveAccessoryComponent(component);
} catch (err) {
  if ((err as Error).message.startsWith('Cannot properly serialize section accessory')) {
    console.warn('Unsupported section accessory; only Button and Thumbnail are allowed.');
  } else throw err;
}

Prevention

When it happens

Trigger: Constructing or resolving a SectionBuilder with an accessory component whose `component.type` is neither ComponentType.Button nor ComponentType.Thumbnail — e.g. a raw API section payload with an unexpected accessory type from a newer API version.

Common situations: Forwarding/echoing raw API message data where sections carry newer accessory types; hand-assembled section JSON putting the wrong component in the accessory slot; outdated library after new accessory kinds were added.

Related errors


AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30). Data as JSON: /api/errors/73381dd49e2340fa. Report an issue: GitHub.