mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
refactor: builders (#10448)
BREAKING CHANGE: formatters export removed (prev. deprecated) BREAKING CHANGE: `SelectMenuBuilder` and `SelectMenuOptionBuilder` have been removed (prev. deprecated) BREAKING CHANGE: `EmbedBuilder` no longer takes camalCase options BREAKING CHANGE: `ActionRowBuilder` now has specialized `[add/set]X` methods as opposed to the current `[add/set]Components` BREAKING CHANGE: Removed `equals` methods BREAKING CHANGE: Sapphire -> zod for validation BREAKING CHANGE: Removed the ability to pass `null`/`undefined` to clear fields, use `clearX()` instead BREAKING CHANGE: Renamed all "slash command" symbols to instead use "chat input command" BREAKING CHANGE: Removed `ContextMenuCommandBuilder` in favor of `MessageCommandBuilder` and `UserCommandBuilder` BREAKING CHANGE: Removed support for passing the "string key"s of enums BREAKING CHANGE: Removed `Button` class in favor for specialized classes depending on the style BREAKING CHANGE: Removed nested `addX` styled-methods in favor of plural `addXs` Co-authored-by: Vlad Frangu <me@vladfrangu.dev> Co-authored-by: Almeida <github@almeidx.dev>
This commit is contained in:
69
packages/builders/src/components/button/CustomIdButton.ts
Normal file
69
packages/builders/src/components/button/CustomIdButton.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { ButtonStyle, ComponentType, type APIButtonComponentWithCustomId } from 'discord-api-types/v10';
|
||||
import { Mixin } from 'ts-mixer';
|
||||
import { BaseButtonBuilder } from './Button.js';
|
||||
import { EmojiOrLabelButtonMixin } from './mixins/EmojiOrLabelButtonMixin.js';
|
||||
|
||||
export type CustomIdButtonStyle = APIButtonComponentWithCustomId['style'];
|
||||
|
||||
/**
|
||||
* A builder that creates API-compatible JSON data for buttons with custom IDs.
|
||||
*/
|
||||
export abstract class CustomIdButtonBuilder extends Mixin(
|
||||
BaseButtonBuilder<APIButtonComponentWithCustomId>,
|
||||
EmojiOrLabelButtonMixin,
|
||||
) {
|
||||
protected override readonly data: Partial<APIButtonComponentWithCustomId>;
|
||||
|
||||
protected constructor(data: Partial<APIButtonComponentWithCustomId> = {}) {
|
||||
super();
|
||||
this.data = { ...structuredClone(data), type: ComponentType.Button };
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the custom id for this button.
|
||||
*
|
||||
* @remarks
|
||||
* This method is only applicable to buttons that are not using the `Link` button style.
|
||||
* @param customId - The custom id to use
|
||||
*/
|
||||
public setCustomId(customId: string) {
|
||||
this.data.custom_id = customId;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A builder that creates API-compatible JSON data for buttons with custom IDs (using the primary style).
|
||||
*/
|
||||
export class PrimaryButtonBuilder extends CustomIdButtonBuilder {
|
||||
public constructor(data: Partial<APIButtonComponentWithCustomId> = {}) {
|
||||
super({ ...data, style: ButtonStyle.Primary });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A builder that creates API-compatible JSON data for buttons with custom IDs (using the secondary style).
|
||||
*/
|
||||
export class SecondaryButtonBuilder extends CustomIdButtonBuilder {
|
||||
public constructor(data: Partial<APIButtonComponentWithCustomId> = {}) {
|
||||
super({ ...data, style: ButtonStyle.Secondary });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A builder that creates API-compatible JSON data for buttons with custom IDs (using the success style).
|
||||
*/
|
||||
export class SuccessButtonBuilder extends CustomIdButtonBuilder {
|
||||
public constructor(data: Partial<APIButtonComponentWithCustomId> = {}) {
|
||||
super({ ...data, style: ButtonStyle.Success });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A builder that creates API-compatible JSON data for buttons with custom IDs (using the danger style).
|
||||
*/
|
||||
export class DangerButtonBuilder extends CustomIdButtonBuilder {
|
||||
public constructor(data: Partial<APIButtonComponentWithCustomId> = {}) {
|
||||
super({ ...data, style: ButtonStyle.Danger });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user