diff --git a/.changeset/serious-gifts-attack.md b/.changeset/serious-gifts-attack.md new file mode 100644 index 00000000..3f1698fd --- /dev/null +++ b/.changeset/serious-gifts-attack.md @@ -0,0 +1,5 @@ +--- +"@buape/carbon": patch +--- + +fix: don't require the user to cast types for button styles diff --git a/apps/rocko/src/commands/testing/button.ts b/apps/rocko/src/commands/testing/button.ts index a93f76d0..16b42c9e 100644 --- a/apps/rocko/src/commands/testing/button.ts +++ b/apps/rocko/src/commands/testing/button.ts @@ -26,7 +26,7 @@ export default class ButtonCommand extends Command { class PingButton extends Button { customId = "ping" label = "Ping" - style = ButtonStyle.Primary as typeof Button.prototype.style + style = ButtonStyle.Primary async run(interaction: ButtonInteraction) { await interaction.reply({ content: "OMG YOU CLICKED THE BUTTON" }) diff --git a/packages/carbon/src/classes/Button.ts b/packages/carbon/src/classes/Button.ts index abc88f5a..6a504f5c 100644 --- a/packages/carbon/src/classes/Button.ts +++ b/packages/carbon/src/classes/Button.ts @@ -37,14 +37,19 @@ abstract class BaseButton extends BaseComponent { } export abstract class Button extends BaseButton { - /** - * The style of the button - */ - abstract style: Exclude - abstract run(interaction: ButtonInteraction): Promise serialize = (): APIButtonComponent => { + if (this.style === ButtonStyle.Link) { + throw new Error( + "Link buttons cannot be serialized. Are you using the right class?" + ) + } + if (this.style === ButtonStyle.Premium) { + throw new Error( + "Premium buttons cannot be serialized. Are you using the right class?" + ) + } return { type: ComponentType.Button, style: this.style,