UNPKG

@confis/discordapiwrapper

Version:

A fast and lightweight discord api wrapper.

787 lines (776 loc) 31.6 kB
require('axios'); require('ws'); require('assert'); require('console'); /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function __classPrivateFieldGet(receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); } function __classPrivateFieldSet(receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; } typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { var e = new Error(message); return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; }; /** Enum for types of webhook */ var WebhookTypes; (function (WebhookTypes) { WebhookTypes[WebhookTypes["INCOMING"] = 1] = "INCOMING"; WebhookTypes[WebhookTypes["CHANNEL_FOLLOWER"] = 2] = "CHANNEL_FOLLOWER"; WebhookTypes[WebhookTypes["APPLICATION"] = 3] = "APPLICATION"; })(WebhookTypes || (WebhookTypes = {})); /** Enum for types of interaction contexts */ var InteractionContextTypes; (function (InteractionContextTypes) { InteractionContextTypes[InteractionContextTypes["GUILD"] = 0] = "GUILD"; InteractionContextTypes[InteractionContextTypes["BOT_DM"] = 1] = "BOT_DM"; InteractionContextTypes[InteractionContextTypes["PRIVATE_CHANNEL"] = 2] = "PRIVATE_CHANNEL"; })(InteractionContextTypes || (InteractionContextTypes = {})); /** Enum for types of interaction integration */ var InteractionIntegrationTypes; (function (InteractionIntegrationTypes) { InteractionIntegrationTypes[InteractionIntegrationTypes["GUILD_INSTALL"] = 0] = "GUILD_INSTALL"; InteractionIntegrationTypes[InteractionIntegrationTypes["USER_INSTALL"] = 1] = "USER_INSTALL"; })(InteractionIntegrationTypes || (InteractionIntegrationTypes = {})); /** Enum for types of message */ var APIMessageTypes; (function (APIMessageTypes) { APIMessageTypes[APIMessageTypes["DEFAULT"] = 0] = "DEFAULT"; APIMessageTypes[APIMessageTypes["RECIPIENT_ADD"] = 1] = "RECIPIENT_ADD"; APIMessageTypes[APIMessageTypes["RECIPIENT_REMOVE"] = 2] = "RECIPIENT_REMOVE"; APIMessageTypes[APIMessageTypes["CALL"] = 3] = "CALL"; APIMessageTypes[APIMessageTypes["CHANNEL_NAME_CHANGE"] = 4] = "CHANNEL_NAME_CHANGE"; APIMessageTypes[APIMessageTypes["CHANNEL_ICON_CHANGE"] = 5] = "CHANNEL_ICON_CHANGE"; APIMessageTypes[APIMessageTypes["CHANNEL_PINNED_MESSAGE"] = 6] = "CHANNEL_PINNED_MESSAGE"; APIMessageTypes[APIMessageTypes["USER_JOIN"] = 7] = "USER_JOIN"; APIMessageTypes[APIMessageTypes["GUILD_BOOST"] = 8] = "GUILD_BOOST"; APIMessageTypes[APIMessageTypes["GUILD_BOOST_TIER_1"] = 9] = "GUILD_BOOST_TIER_1"; APIMessageTypes[APIMessageTypes["GUILD_BOOST_TIER_2"] = 10] = "GUILD_BOOST_TIER_2"; APIMessageTypes[APIMessageTypes["GUILD_BOOST_TIER_3"] = 11] = "GUILD_BOOST_TIER_3"; APIMessageTypes[APIMessageTypes["CHANNEL_FOLLOW_ADD"] = 12] = "CHANNEL_FOLLOW_ADD"; APIMessageTypes[APIMessageTypes["GUILD_DISCOVERY_DISQUALIFIED"] = 14] = "GUILD_DISCOVERY_DISQUALIFIED"; APIMessageTypes[APIMessageTypes["GUILD_DISCOVERY_REQUALIFIED"] = 15] = "GUILD_DISCOVERY_REQUALIFIED"; APIMessageTypes[APIMessageTypes["GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING"] = 16] = "GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING"; APIMessageTypes[APIMessageTypes["GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING"] = 17] = "GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING"; APIMessageTypes[APIMessageTypes["THREAD_CREATED"] = 18] = "THREAD_CREATED"; APIMessageTypes[APIMessageTypes["REPLY"] = 19] = "REPLY"; APIMessageTypes[APIMessageTypes["CHAT_INPUT_COMMAND"] = 20] = "CHAT_INPUT_COMMAND"; APIMessageTypes[APIMessageTypes["THREAD_STARTER_MESSAGE"] = 21] = "THREAD_STARTER_MESSAGE"; APIMessageTypes[APIMessageTypes["GUILD_INVITE_REMINDER"] = 22] = "GUILD_INVITE_REMINDER"; APIMessageTypes[APIMessageTypes["CONTEXT_MENU_COMMAND"] = 23] = "CONTEXT_MENU_COMMAND"; APIMessageTypes[APIMessageTypes["AUTO_MODERATION_ACTION"] = 24] = "AUTO_MODERATION_ACTION"; APIMessageTypes[APIMessageTypes["ROLE_SUBSCRIPTION_PURCHASE"] = 25] = "ROLE_SUBSCRIPTION_PURCHASE"; APIMessageTypes[APIMessageTypes["INTERACTION_PREMIUM_UPSELL"] = 26] = "INTERACTION_PREMIUM_UPSELL"; APIMessageTypes[APIMessageTypes["STAGE_START"] = 27] = "STAGE_START"; APIMessageTypes[APIMessageTypes["STAGE_END"] = 28] = "STAGE_END"; APIMessageTypes[APIMessageTypes["STAGE_SPEAKER"] = 29] = "STAGE_SPEAKER"; APIMessageTypes[APIMessageTypes["STAGE_TOPIC"] = 31] = "STAGE_TOPIC"; APIMessageTypes[APIMessageTypes["GUILD_APPLICATION_PREMIUM_SUBSCRIPTION"] = 32] = "GUILD_APPLICATION_PREMIUM_SUBSCRIPTION"; APIMessageTypes[APIMessageTypes["GUILD_INCIDENT_ALERT_MODE_ENABLED"] = 36] = "GUILD_INCIDENT_ALERT_MODE_ENABLED"; APIMessageTypes[APIMessageTypes["GUILD_INCIDENT_ALERT_MODE_DISABLED"] = 37] = "GUILD_INCIDENT_ALERT_MODE_DISABLED"; APIMessageTypes[APIMessageTypes["GUILD_INCIDENT_REPORT_RAID"] = 38] = "GUILD_INCIDENT_REPORT_RAID"; APIMessageTypes[APIMessageTypes["GUILD_INCIDENT_REPORT_FALSE_ALARM"] = 39] = "GUILD_INCIDENT_REPORT_FALSE_ALARM"; APIMessageTypes[APIMessageTypes["PURCHASE_NOTIFICATION"] = 44] = "PURCHASE_NOTIFICATION"; APIMessageTypes[APIMessageTypes["POLL_RESULT"] = 46] = "POLL_RESULT"; })(APIMessageTypes || (APIMessageTypes = {})); /** * Enum for types of application commands */ var ApplicationCommandTypes; (function (ApplicationCommandTypes) { ApplicationCommandTypes[ApplicationCommandTypes["CHAT_INPUT"] = 1] = "CHAT_INPUT"; ApplicationCommandTypes[ApplicationCommandTypes["USER"] = 2] = "USER"; ApplicationCommandTypes[ApplicationCommandTypes["MESSAGE"] = 3] = "MESSAGE"; })(ApplicationCommandTypes || (ApplicationCommandTypes = {})); /** * Enum for types of interactions */ var InteractionTypes; (function (InteractionTypes) { InteractionTypes[InteractionTypes["PING"] = 1] = "PING"; InteractionTypes[InteractionTypes["APPLICATION_COMMAND"] = 2] = "APPLICATION_COMMAND"; InteractionTypes[InteractionTypes["MESSAGE_COMPONENT"] = 3] = "MESSAGE_COMPONENT"; InteractionTypes[InteractionTypes["APPLICATION_COMMAND_AUTOCOMPLETE"] = 4] = "APPLICATION_COMMAND_AUTOCOMPLETE"; InteractionTypes[InteractionTypes["MODAL_SUBMIT"] = 5] = "MODAL_SUBMIT"; })(InteractionTypes || (InteractionTypes = {})); /** * Enum for types of components */ var ComponentTypes; (function (ComponentTypes) { ComponentTypes[ComponentTypes["ACTION_ROW"] = 1] = "ACTION_ROW"; ComponentTypes[ComponentTypes["BUTTON"] = 2] = "BUTTON"; ComponentTypes[ComponentTypes["STRING_SELECT"] = 3] = "STRING_SELECT"; ComponentTypes[ComponentTypes["TEXT_INPUT"] = 4] = "TEXT_INPUT"; })(ComponentTypes || (ComponentTypes = {})); /** * Enum for types of button styles */ var ButtonStyles; (function (ButtonStyles) { ButtonStyles[ButtonStyles["PRIMARY"] = 1] = "PRIMARY"; ButtonStyles[ButtonStyles["SECONDARY"] = 2] = "SECONDARY"; ButtonStyles[ButtonStyles["SUCCESS"] = 3] = "SUCCESS"; ButtonStyles[ButtonStyles["DANGER"] = 4] = "DANGER"; ButtonStyles[ButtonStyles["LINK"] = 5] = "LINK"; })(ButtonStyles || (ButtonStyles = {})); /** * Enum for types of activity */ var ActivityTypes; (function (ActivityTypes) { ActivityTypes[ActivityTypes["GAME"] = 0] = "GAME"; ActivityTypes[ActivityTypes["STREAMING"] = 1] = "STREAMING"; ActivityTypes[ActivityTypes["LISTENING"] = 2] = "LISTENING"; ActivityTypes[ActivityTypes["WATCHING"] = 3] = "WATCHING"; ActivityTypes[ActivityTypes["CUSTOM"] = 4] = "CUSTOM"; ActivityTypes[ActivityTypes["COMPETING"] = 5] = "COMPETING"; })(ActivityTypes || (ActivityTypes = {})); /** * Enum for types of application command options */ var ApplicationCommandOptionTypes; (function (ApplicationCommandOptionTypes) { ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["SUB_COMMAND"] = 1] = "SUB_COMMAND"; ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["SUB_COMMAND_GROUP"] = 2] = "SUB_COMMAND_GROUP"; ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["STRING"] = 3] = "STRING"; ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["INTEGER"] = 4] = "INTEGER"; ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["BOOLEAN"] = 5] = "BOOLEAN"; ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["USER"] = 6] = "USER"; ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["CHANNEL"] = 7] = "CHANNEL"; ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["ROLE"] = 8] = "ROLE"; ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["MENTIONABLE"] = 9] = "MENTIONABLE"; ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["NUMBER"] = 10] = "NUMBER"; ApplicationCommandOptionTypes[ApplicationCommandOptionTypes["ATTACHMENT"] = 11] = "ATTACHMENT"; })(ApplicationCommandOptionTypes || (ApplicationCommandOptionTypes = {})); /** * Enum for types of channels */ var ChannelTypes; (function (ChannelTypes) { ChannelTypes[ChannelTypes["TEXT"] = 0] = "TEXT"; ChannelTypes[ChannelTypes["DM"] = 1] = "DM"; ChannelTypes[ChannelTypes["CATEGORY"] = 4] = "CATEGORY"; })(ChannelTypes || (ChannelTypes = {})); var OverwriteObjectTypes; (function (OverwriteObjectTypes) { OverwriteObjectTypes[OverwriteObjectTypes["ROLE"] = 0] = "ROLE"; OverwriteObjectTypes[OverwriteObjectTypes["MEMBER"] = 1] = "MEMBER"; })(OverwriteObjectTypes || (OverwriteObjectTypes = {})); /** Enum of types of messages */ var MessageTypes; (function (MessageTypes) { MessageTypes[MessageTypes["DEFAULT"] = 0] = "DEFAULT"; MessageTypes[MessageTypes["USER_JOIN"] = 7] = "USER_JOIN"; MessageTypes[MessageTypes["REPLY"] = 19] = "REPLY"; })(MessageTypes || (MessageTypes = {})); /** Bot Intents */ var Intents; (function (Intents) { Intents[Intents["GUILDS"] = 1] = "GUILDS"; Intents[Intents["GUILD_MEMBERS"] = 2] = "GUILD_MEMBERS"; Intents[Intents["GUILD_BANS"] = 4] = "GUILD_BANS"; Intents[Intents["GUILD_EMOJIS_AND_STICKERS"] = 8] = "GUILD_EMOJIS_AND_STICKERS"; Intents[Intents["GUILD_INTEGRATIONS"] = 16] = "GUILD_INTEGRATIONS"; Intents[Intents["GUILD_WEBHOOKS"] = 32] = "GUILD_WEBHOOKS"; Intents[Intents["GUILD_INVITES"] = 64] = "GUILD_INVITES"; Intents[Intents["GUILD_VOICE_STATES"] = 128] = "GUILD_VOICE_STATES"; Intents[Intents["GUILD_PRESENCES"] = 256] = "GUILD_PRESENCES"; Intents[Intents["GUILD_MESSAGES"] = 512] = "GUILD_MESSAGES"; Intents[Intents["GUILD_MESSAGE_REACTIONS"] = 1024] = "GUILD_MESSAGE_REACTIONS"; Intents[Intents["GUILD_MESSAGE_TYPING"] = 2048] = "GUILD_MESSAGE_TYPING"; Intents[Intents["DIRECT_MESSAGES"] = 4096] = "DIRECT_MESSAGES"; Intents[Intents["DIRECT_MESSAGE_REACTIONS"] = 8192] = "DIRECT_MESSAGE_REACTIONS"; Intents[Intents["DIRECT_MESSAGE_TYPING"] = 16384] = "DIRECT_MESSAGE_TYPING"; Intents[Intents["MESSAGE_CONTENT"] = 32768] = "MESSAGE_CONTENT"; Intents[Intents["GUILD_SCHEDULED_EVENTS"] = 65536] = "GUILD_SCHEDULED_EVENTS"; Intents[Intents["ALL"] = 131071] = "ALL"; })(Intents || (Intents = {})); var _ButtonBuilder_label, _ButtonBuilder_style, _ButtonBuilder_custom_id, _ButtonBuilder_disabled, _ButtonBuilder_emoji, _ButtonBuilder_url, _StringSelectMenuBuilder_placeHolder, _StringSelectMenuBuilder_custom_id, _StringSelectMenuBuilder_disabled, _StringSelect_label, _StringSelect_value, _StringSelect_description, _StringSelect_emoji, _StringSelect_default, _TextInputBuilder_custom_id, _TextInputBuilder_label, _TextInputBuilder_style, _TextInputBuilder_min_length, _TextInputBuilder_max_length, _TextInputBuilder_required, _TextInputBuilder_value, _TextInputBuilder_placeholder, _ModalBuilder_title, _ModalBuilder_custom_id, _ModalBuilder_components; /** Embed builder */ class EmbedBuilder { /** * Set the author of the embed * @param options Author Options * @returns EmbedBuilder Object */ setAuthor(options) { this.author = options; return this; } /** * Set the timestamp of the embed * @param date The timestamp date * @returns EmbedBuilder Object */ setTimestamp(date) { this.timestamp = date || new Date(); return this; } /** * Set the title of the embed * @param title The title of the embed * @returns EmbedBuilder Object */ setTitle(title) { this.title = title; return this; } /** * Set the Color of the embed * @param color The color of the embed in decial or hex * @returns EmbedBuilder Object */ setColor(color) { if (typeof color === "number") { this.color = color; } else { this.color = parseInt(color.replace("#", ""), 16); } return this; } /** * Set the Description of the embed * @param description The description of the embed * @returns EmbedBuilder Object */ setDescription(description) { this.description = description; return this; } /** * Set the Thumbnail of the embed * @param options {@link ImageOptions} * @returns EmbedBuilder Object */ setThumbnail(options) { this.thumbnail = options; return this; } /** * Set the Image of the embed * @param options {@link ImageOptions} * @returns EmbedBuilder Object */ setImage(options) { this.image = options; return this; } /** * Set the Footer of the embed * @param options {@link FooterOptions} * @returns EmbedBuilder Object */ setFooter(options) { this.footer = options; return this; } /** * Set the Fields of the embed * @param fields {@link FieldOptions} * @returns EmbedBuilder Object */ setFields(fields) { this.fields = fields; return this; } /** * Add one or more fields to the embed * @param fields The fields to add * @returns EmbedBuilder Object */ addFields(...fields) { if (!this.fields) { this.fields = []; } this.fields.push(...fields); return this; } /** * Set the URL of the embed * @param url The URL * @returns EmbedBuilder Object */ setURL(url) { this.url = url; return this; } toJson() { return { author: this.author, color: this.color, description: this.description, fields: this.fields, footer: this.footer, image: this.image, thumbnail: this.thumbnail, timestamp: this.timestamp, title: this.title, url: this.url, }; } } /** Button builder */ class ButtonBuilder { constructor() { _ButtonBuilder_label.set(this, void 0); _ButtonBuilder_style.set(this, ButtonStyles.PRIMARY); _ButtonBuilder_custom_id.set(this, void 0); _ButtonBuilder_disabled.set(this, false); _ButtonBuilder_emoji.set(this, void 0); _ButtonBuilder_url.set(this, void 0); } /** * Set the URL of the button * @param url the URL * @returns ButtonBuilder Object */ setUrl(url) { __classPrivateFieldSet(this, _ButtonBuilder_url, url, "f"); return this; } /** * Set the Label of the button * @param label the Label * @returns ButtonBuilder Object */ setLabel(label) { __classPrivateFieldSet(this, _ButtonBuilder_label, label, "f"); return this; } /** * Set the Style of the button * @param style {@link ButtonStyles} * @returns ButtonBuilder Object */ setStyle(style) { __classPrivateFieldSet(this, _ButtonBuilder_style, style, "f"); return this; } /** * Set the Custom ID of the button * @param id The custom ID * @returns ButtonBuilder Object */ setCustomID(id) { __classPrivateFieldSet(this, _ButtonBuilder_custom_id, id, "f"); return this; } /** * Set if the button is disabled * @param disabled Disabled field * @returns ButtonBuilder Object */ setDisabled(disabled) { __classPrivateFieldSet(this, _ButtonBuilder_disabled, disabled, "f"); return this; } /** * Set the emoji of the button * @param emoji The emoji * @returns ButtonBuilder Object */ setEmoji(emoji) { if (emoji.includes("<")) { const name = emoji.split(":")[1]; const id = emoji.split(":")[2].replace(">", ""); __classPrivateFieldSet(this, _ButtonBuilder_emoji, { name, id, }, "f"); } else { __classPrivateFieldSet(this, _ButtonBuilder_emoji, { name: emoji, }, "f"); } return this; } toJson() { return { type: 2, label: __classPrivateFieldGet(this, _ButtonBuilder_label, "f"), style: __classPrivateFieldGet(this, _ButtonBuilder_style, "f"), custom_id: __classPrivateFieldGet(this, _ButtonBuilder_custom_id, "f"), disabled: __classPrivateFieldGet(this, _ButtonBuilder_disabled, "f"), emoji: __classPrivateFieldGet(this, _ButtonBuilder_emoji, "f"), url: __classPrivateFieldGet(this, _ButtonBuilder_url, "f"), }; } } _ButtonBuilder_label = new WeakMap(), _ButtonBuilder_style = new WeakMap(), _ButtonBuilder_custom_id = new WeakMap(), _ButtonBuilder_disabled = new WeakMap(), _ButtonBuilder_emoji = new WeakMap(), _ButtonBuilder_url = new WeakMap(); /** String select menu builder */ class StringSelectMenuBuilder { constructor() { _StringSelectMenuBuilder_placeHolder.set(this, void 0); _StringSelectMenuBuilder_custom_id.set(this, void 0); _StringSelectMenuBuilder_disabled.set(this, false); } /** * Set the Placeholder of the StringSelectMenu * @param placeholder The placeholder * @returns StringSelectMenuBuilder Object */ setPlaceholder(placeholder) { __classPrivateFieldSet(this, _StringSelectMenuBuilder_placeHolder, placeholder, "f"); return this; } /** * Set the Custom ID of the StringSelectMenu * @param id The custom ID * @returns StringSelectMenuBuilder Object */ setCustomID(id) { __classPrivateFieldSet(this, _StringSelectMenuBuilder_custom_id, id, "f"); return this; } /** * Set if the menu is disabled * @param disabled Disabled field * @returns StringSelectMenuBuilder Object */ setDisabled(disabled) { __classPrivateFieldSet(this, _StringSelectMenuBuilder_disabled, disabled, "f"); return this; } /** * Set the options of the StringSelectMenu * @param ...args An array of {@link StringSelect} * @returns StringSelectMenuBuilder Object */ setOptions(...args) { this.options = args; return this; } toJson() { const optionsJSON = []; for (let i = 0; i < this.options.length; i++) { optionsJSON.push(this.options[i].toJson()); } return { type: 3, custom_id: __classPrivateFieldGet(this, _StringSelectMenuBuilder_custom_id, "f"), options: optionsJSON, placeholder: __classPrivateFieldGet(this, _StringSelectMenuBuilder_placeHolder, "f"), disabled: __classPrivateFieldGet(this, _StringSelectMenuBuilder_disabled, "f"), }; } } _StringSelectMenuBuilder_placeHolder = new WeakMap(), _StringSelectMenuBuilder_custom_id = new WeakMap(), _StringSelectMenuBuilder_disabled = new WeakMap(); /** String select object */ class StringSelect { constructor() { _StringSelect_label.set(this, void 0); _StringSelect_value.set(this, void 0); _StringSelect_description.set(this, void 0); _StringSelect_emoji.set(this, void 0); _StringSelect_default.set(this, void 0); } /** * Set the Label of the StringSelect * @param label The label * @returns StringSelect Object */ setLabel(label) { __classPrivateFieldSet(this, _StringSelect_label, label, "f"); return this; } /** * Set the Value of the StringSelect * @param value The value * @returns StringSelect Object */ setValue(value) { __classPrivateFieldSet(this, _StringSelect_value, value, "f"); return this; } /** * Set the Description of the StringSelect * @param description The description * @returns StringSelect Object */ setDescription(description) { __classPrivateFieldSet(this, _StringSelect_description, description, "f"); return this; } /** * Set the Emoji of the StringSelect * @param emoji The emoji * @returns StringSelect Object */ setEmoji(emoji) { if (emoji.includes("<")) { const name = emoji.split(":")[1]; const id = emoji.split(":")[2].replace(">", ""); __classPrivateFieldSet(this, _StringSelect_emoji, { name, id, }, "f"); } else { __classPrivateFieldSet(this, _StringSelect_emoji, { name: emoji, }, "f"); } return this; } /** * Set if the string select is default * @param value Default value * @returns StringSelect Object */ setDefault(value) { __classPrivateFieldSet(this, _StringSelect_default, value, "f"); return this; } toJson() { return { label: __classPrivateFieldGet(this, _StringSelect_label, "f"), value: __classPrivateFieldGet(this, _StringSelect_value, "f"), description: __classPrivateFieldGet(this, _StringSelect_description, "f"), emoji: __classPrivateFieldGet(this, _StringSelect_emoji, "f"), default: __classPrivateFieldGet(this, _StringSelect_default, "f"), }; } } _StringSelect_label = new WeakMap(), _StringSelect_value = new WeakMap(), _StringSelect_description = new WeakMap(), _StringSelect_emoji = new WeakMap(), _StringSelect_default = new WeakMap(); /** Action Row builder */ class ActionRowBuilder { /** * Set the Components of the ActionRow * @param ...args An array of {@link SUPPORTED_ELEMENTS} * @returns ActionRowBuilder Object */ setComponents(...args) { this.components = args; return this; } /** * Add components to the ActionRow * @param args An array of components to add * @returns ActionRowBuilder Object for method chaining */ addComponents(...args) { this.components.push(...args); return this; } /** * Disables all components in the action row * @returns The ActionRowBuilder instance for method chaining */ disableAllComponents() { for (const component of this.components) { if (!(component instanceof TextInputBuilder)) { component.setDisabled(true); } } return this; } /** * Set the Components of the ActionRow * @param components An array of {@link SUPPORTED_ELEMENTS} * @returns ActionRowBuilder Object */ setComponentsArray(components) { this.components = components; return this; } toJson() { const JSONArray = []; for (let i = 0; i < this.components.length; i++) { const component = this.components[i]; JSONArray.push(component.toJson()); } return { type: 1, components: JSONArray, }; } } /** Text input styles enum */ exports.TextInputStyles = void 0; (function (TextInputStyles) { TextInputStyles[TextInputStyles["SHORT"] = 1] = "SHORT"; TextInputStyles[TextInputStyles["PARAGRAPH"] = 2] = "PARAGRAPH"; })(exports.TextInputStyles || (exports.TextInputStyles = {})); /** Text input builder */ class TextInputBuilder { constructor() { _TextInputBuilder_custom_id.set(this, void 0); _TextInputBuilder_label.set(this, void 0); _TextInputBuilder_style.set(this, exports.TextInputStyles.SHORT); _TextInputBuilder_min_length.set(this, void 0); _TextInputBuilder_max_length.set(this, void 0); _TextInputBuilder_required.set(this, false); _TextInputBuilder_value.set(this, void 0); _TextInputBuilder_placeholder.set(this, void 0); } /** * Set the Custom ID of the text input * @param id The custom ID * @returns TextInputBuilder Object */ setCustomID(id) { __classPrivateFieldSet(this, _TextInputBuilder_custom_id, id, "f"); return this; } /** * Set the Label of the text input * @param label The label * @returns TextInputBuilder Object */ setLabel(label) { __classPrivateFieldSet(this, _TextInputBuilder_label, label, "f"); return this; } /** * Set the Style of the text input * @param style The style from TextInputStyles * @returns TextInputBuilder Object */ setStyle(style) { __classPrivateFieldSet(this, _TextInputBuilder_style, style, "f"); return this; } /** * Set the Minimum Length of the text input * @param length The minimum length * @returns TextInputBuilder Object */ setMinLength(length) { __classPrivateFieldSet(this, _TextInputBuilder_min_length, length, "f"); return this; } /** * Set the Maximum Length of the text input * @param length The maximum length * @returns TextInputBuilder Object */ setMaxLength(length) { __classPrivateFieldSet(this, _TextInputBuilder_max_length, length, "f"); return this; } /** * Set if the text input is required * @param required Whether the field is required * @returns TextInputBuilder Object */ setRequired(required) { __classPrivateFieldSet(this, _TextInputBuilder_required, required, "f"); return this; } /** * Set the Value of the text input * @param value The pre-filled value * @returns TextInputBuilder Object */ setValue(value) { __classPrivateFieldSet(this, _TextInputBuilder_value, value, "f"); return this; } /** * Set the Placeholder of the text input * @param placeholder The placeholder text * @returns TextInputBuilder Object */ setPlaceholder(placeholder) { __classPrivateFieldSet(this, _TextInputBuilder_placeholder, placeholder, "f"); return this; } toJson() { return { type: 4, custom_id: __classPrivateFieldGet(this, _TextInputBuilder_custom_id, "f"), label: __classPrivateFieldGet(this, _TextInputBuilder_label, "f"), style: __classPrivateFieldGet(this, _TextInputBuilder_style, "f"), min_length: __classPrivateFieldGet(this, _TextInputBuilder_min_length, "f"), max_length: __classPrivateFieldGet(this, _TextInputBuilder_max_length, "f"), required: __classPrivateFieldGet(this, _TextInputBuilder_required, "f"), value: __classPrivateFieldGet(this, _TextInputBuilder_value, "f"), placeholder: __classPrivateFieldGet(this, _TextInputBuilder_placeholder, "f"), }; } } _TextInputBuilder_custom_id = new WeakMap(), _TextInputBuilder_label = new WeakMap(), _TextInputBuilder_style = new WeakMap(), _TextInputBuilder_min_length = new WeakMap(), _TextInputBuilder_max_length = new WeakMap(), _TextInputBuilder_required = new WeakMap(), _TextInputBuilder_value = new WeakMap(), _TextInputBuilder_placeholder = new WeakMap(); /** Modal builder */ class ModalBuilder { constructor() { _ModalBuilder_title.set(this, void 0); _ModalBuilder_custom_id.set(this, void 0); _ModalBuilder_components.set(this, []); } /** * Set the Title of the modal * @param title The title * @returns ModalBuilder Object */ setTitle(title) { __classPrivateFieldSet(this, _ModalBuilder_title, title, "f"); return this; } /** * Set the Custom ID of the modal * @param id The custom ID * @returns ModalBuilder Object */ setCustomID(id) { __classPrivateFieldSet(this, _ModalBuilder_custom_id, id, "f"); return this; } /** * Add components to the modal * @param components The components to add * @returns ModalBuilder Object */ addComponents(components) { __classPrivateFieldGet(this, _ModalBuilder_components, "f").push(...components.components); return this; } /** * Set the components of the modal * @param components The components to set * @returns ModalBuilder Object */ setComponents(components) { __classPrivateFieldSet(this, _ModalBuilder_components, components.components, "f"); return this; } toJson() { return { title: __classPrivateFieldGet(this, _ModalBuilder_title, "f"), custom_id: __classPrivateFieldGet(this, _ModalBuilder_custom_id, "f"), type: 1, components: __classPrivateFieldGet(this, _ModalBuilder_components, "f").map(component => ({ type: 1, components: [component.toJson()] })) }; } } _ModalBuilder_title = new WeakMap(), _ModalBuilder_custom_id = new WeakMap(), _ModalBuilder_components = new WeakMap(); exports.ActionRowBuilder = ActionRowBuilder; exports.ButtonBuilder = ButtonBuilder; exports.EmbedBuilder = EmbedBuilder; exports.ModalBuilder = ModalBuilder; exports.StringSelect = StringSelect; exports.StringSelectMenuBuilder = StringSelectMenuBuilder; exports.TextInputBuilder = TextInputBuilder;