{"record":{"id":"4d09e389a0e6bfa0","repo":"discordjs/discord.js","slug":"cannot-properly-serialize-button-with-style-dat","errorCode":null,"errorMessage":"Cannot properly serialize button with style: ${data.style}","messagePattern":"Cannot properly serialize button with style: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/builders/src/components/Components.ts","lineNumber":262,"sourceCode":"}\n\nfunction createButtonBuilder(data: APIButtonComponent): ButtonBuilder {\n\tswitch (data.style) {\n\t\tcase ButtonStyle.Primary:\n\t\t\treturn new PrimaryButtonBuilder(data);\n\t\tcase ButtonStyle.Secondary:\n\t\t\treturn new SecondaryButtonBuilder(data);\n\t\tcase ButtonStyle.Success:\n\t\t\treturn new SuccessButtonBuilder(data);\n\t\tcase ButtonStyle.Danger:\n\t\t\treturn new DangerButtonBuilder(data);\n\t\tcase ButtonStyle.Link:\n\t\t\treturn new LinkButtonBuilder(data);\n\t\tcase ButtonStyle.Premium:\n\t\t\treturn new PremiumButtonBuilder(data);\n\t\tdefault:\n\t\t\t// @ts-expect-error This case can still occur if we get a newer unsupported button style\n\t\t\tthrow new Error(`Cannot properly serialize button with style: ${data.style}`);\n\t}\n}\n\nexport function resolveAccessoryComponent(component: APISectionAccessoryComponent) {\n\tswitch (component.type) {\n\t\tcase ComponentType.Button:\n\t\t\treturn createButtonBuilder(component);\n\t\tcase ComponentType.Thumbnail:\n\t\t\treturn new ThumbnailBuilder(component);\n\t\tdefault:\n\t\t\t// @ts-expect-error This case can still occur if we get a newer unsupported component type\n\t\t\tthrow new Error(`Cannot properly serialize section accessory component: ${component.type}`);\n\t}\n}\n","sourceCodeStart":244,"sourceCodeEnd":277,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/builders/src/components/Components.ts#L244-L277","documentation":"createButtonBuilder dispatches on the button's `style` to pick the right ButtonBuilder subclass (Link, Premium, etc.). If the style value does not match any supported ButtonStyle, the default branch throws, which normally means the button data uses a style introduced after this library version was released.","triggerScenarios":"Resolving an APIButtonComponent whose `data.style` is a numeric value not present in the supported ButtonStyle set (newer API button style, or invalid style in hand-built component data).","commonSituations":"Receiving messages/interactions created by clients using newer button styles than the installed library supports; constructing button JSON manually with a wrong style number; stale library version after a Discord API update.","solutions":["Update @discordjs/builders / discord.js to the newest version for support of new button styles.","Validate `style` against ButtonStyle before resolving and skip/ignore unsupported buttons.","Fix manually constructed button data to use a valid ButtonStyle value.","Check whether the payload came from a newer client/API and normalize it before building."],"exampleFix":"// before\nconst btn = createButtonBuilder({ style: 42, ... }); // unknown style\n// after\nconst btn = Object.values(ButtonStyle).includes(data.style) ? createButtonBuilder(data) : null;","handlingStrategy":"type-guard","validationCode":"if (!Object.values(ButtonStyle).includes(data.style)) {\n  return null; // skip unsupported button\n}","typeGuard":"function isSupportedButtonStyle(s: number): s is ButtonStyle {\n  return Object.values(ButtonStyle).includes(s as ButtonStyle);\n}","tryCatchPattern":"try {\n  const btn = createButtonBuilder(data);\n} catch (err) {\n  if ((err as Error).message.startsWith('Cannot properly serialize button')) {\n    console.warn(`Unknown button style ${data.style}; skipping.`);\n  } else throw err;\n}","preventionTips":["Use ButtonStyle enum values, never raw numbers, when constructing buttons.","Update the library after Discord adds new button styles.","Filter raw message components through a supported-style check."],"tags":["components","buttons","unsupported-type"],"backgroundTag":"unsupported-component-type","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}