mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
* refactor: don't return builders from API data * Update packages/discord.js/src/structures/ActionRow.js Co-authored-by: Antonio Román <kyradiscord@gmail.com> * fix: circular dependency * fix: circular dependency pt.2 * chore: make requested changes * chore: bump dapi-types * chore: convert text input * chore: convert text input * feat: handle cases of unknown component types better * refactor: refactor modal to builder * feat: add #from for easy builder conversions * refactor: make requested changes * chore: make requested changes * style: fix linting error Co-authored-by: Antonio Román <kyradiscord@gmail.com> Co-authored-by: almeidx <almeidx@pm.me>
82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
import {
|
|
ComponentType,
|
|
ButtonStyle,
|
|
type APIMessageComponentEmoji,
|
|
type APIButtonComponent,
|
|
type APIButtonComponentWithURL,
|
|
type APIButtonComponentWithCustomId,
|
|
} from 'discord-api-types/v9';
|
|
import { ComponentBuilder } from '../Component';
|
|
|
|
/**
|
|
* Represents a non-validated button component
|
|
*/
|
|
export class UnsafeButtonBuilder extends ComponentBuilder<
|
|
Partial<APIButtonComponent> & { type: ComponentType.Button }
|
|
> {
|
|
public constructor(data?: Partial<APIButtonComponent>) {
|
|
super({ type: ComponentType.Button, ...data });
|
|
}
|
|
|
|
/**
|
|
* Sets the style of this button
|
|
* @param style The style of the button
|
|
*/
|
|
public setStyle(style: ButtonStyle) {
|
|
this.data.style = style;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Sets the URL for this button
|
|
* @param url The URL to open when this button is clicked
|
|
*/
|
|
public setURL(url: string) {
|
|
(this.data as APIButtonComponentWithURL).url = url;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Sets the custom Id for this button
|
|
* @param customId The custom id to use for this button
|
|
*/
|
|
public setCustomId(customId: string) {
|
|
(this.data as APIButtonComponentWithCustomId).custom_id = customId;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Sets the emoji to display on this button
|
|
* @param emoji The emoji to display on this button
|
|
*/
|
|
public setEmoji(emoji: APIMessageComponentEmoji) {
|
|
this.data.emoji = emoji;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Sets whether this button is disable or not
|
|
* @param disabled Whether or not to disable this button or not
|
|
*/
|
|
public setDisabled(disabled = true) {
|
|
this.data.disabled = disabled;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Sets the label for this button
|
|
* @param label The label to display on this button
|
|
*/
|
|
public setLabel(label: string) {
|
|
this.data.label = label;
|
|
return this;
|
|
}
|
|
|
|
public toJSON(): APIButtonComponent {
|
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
return {
|
|
...this.data,
|
|
} as APIButtonComponent;
|
|
}
|
|
}
|