v2componentsbuilder
Version:
A discord.js v2components builder
68 lines (67 loc) • 1.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.V2ButtonBuilder = void 0;
const v10_1 = require("discord-api-types/v10");
class V2ButtonBuilder {
constructor() {
}
setCustomId(custom_id) {
if (custom_id.length > 100)
throw Error("Max length for custom ids is 100 characters");
this.custom_id = custom_id;
return this;
}
setLabel(label) {
if (label.length > 80)
throw Error("Max length for custom ids is 100 characters");
this.label = label;
return this;
}
setEmoji(emoji) {
this.emoji = emoji;
return this;
}
setStyle(style) {
this.style = style;
return this;
}
setURL(url) {
this.url = url;
return this;
}
setDisabled(disabled) {
this.disabled = disabled;
return this;
}
setSKU(sku_id) {
this.sku_id = sku_id;
return this;
}
toJSON() {
if (this.style === v10_1.ButtonStyle.Link) {
if (!this.url)
throw new Error("Link buttons must have a URL");
return {
type: v10_1.ComponentType.Button,
style: v10_1.ButtonStyle.Link,
label: this.label,
emoji: this.emoji,
url: this.url,
disabled: this.disabled ?? false,
};
}
else {
if (!this.custom_id)
throw new Error("Non-link buttons must have a custom_id");
return {
type: v10_1.ComponentType.Button,
style: this.style,
custom_id: this.custom_id,
label: this.label,
emoji: this.emoji,
disabled: this.disabled ?? false,
};
}
}
}
exports.V2ButtonBuilder = V2ButtonBuilder;