diff --git a/packages/discord.js/src/structures/SelectMenuBuilder.js b/packages/discord.js/src/structures/SelectMenuBuilder.js index 15d1f9a93..b9322e57d 100644 --- a/packages/discord.js/src/structures/SelectMenuBuilder.js +++ b/packages/discord.js/src/structures/SelectMenuBuilder.js @@ -5,25 +5,53 @@ const Transformers = require('../util/Transformers'); const Util = require('../util/Util'); /** - * Represents a select menu builder. + * Class used to build select menu components to be sent through the API * @extends {BuildersSelectMenu} */ class SelectMenuBuilder extends BuildersSelectMenu { constructor({ options, ...data } = {}) { super( Transformers.toSnakeCase({ + ...data, options: options?.map(({ emoji, ...option }) => ({ ...option, emoji: emoji && typeof emoji === 'string' ? Util.parseEmoji(emoji) : emoji, })), - ...data, }), ); } /** - * Creates a new select menu builder from JSON data - * @param {JSONEncodable|APISelectMenuComponent} other The other data + * Adds options to this select menu + * @param {APISelectMenuOption[]} options The options to add to this select menu + * @returns {SelectMenuBuilder} + */ + addOptions(...options) { + return super.addOptions( + options.map(({ emoji, ...option }) => ({ + ...option, + emoji: emoji && typeof emoji === 'string' ? Util.parseEmoji(emoji) : emoji, + })), + ); + } + + /** + * Sets the options on this select menu + * @param {APISelectMenuOption[]} options The options to set on this select menu + * @returns {SelectMenuBuilder} + */ + setOptions(...options) { + return super.setOptions( + options.map(({ emoji, ...option }) => ({ + ...option, + emoji: emoji && typeof emoji === 'string' ? Util.parseEmoji(emoji) : emoji, + })), + ); + } + + /** + * Creates a new select menu builder from json data + * @param {JSONEncodable | APISelectMenuComponent} other The other data * @returns {SelectMenuBuilder} */ static from(other) { diff --git a/packages/discord.js/src/structures/SelectMenuOptionBuilder.js b/packages/discord.js/src/structures/SelectMenuOptionBuilder.js index 1d2a13f27..ea816bea2 100644 --- a/packages/discord.js/src/structures/SelectMenuOptionBuilder.js +++ b/packages/discord.js/src/structures/SelectMenuOptionBuilder.js @@ -1,6 +1,7 @@ 'use strict'; const { SelectMenuOptionBuilder: BuildersSelectMenuOption } = require('@discordjs/builders'); +const Transformers = require('../util/Transformers'); const Util = require('../util/Util'); /** @@ -8,6 +9,14 @@ const Util = require('../util/Util'); * @extends {BuildersSelectMenuOption} */ class SelectMenuOptionBuilder extends BuildersSelectMenuOption { + constructor({ emoji, ...data } = {}) { + super( + Transformers.toSnakeCase({ + ...data, + emoji: emoji && typeof emoji === 'string' ? Util.parseEmoji(emoji) : emoji, + }), + ); + } /** * Sets the emoji to display on this option * @param {ComponentEmojiResolvable} emoji The emoji to display on this option diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 7567a0528..57db5e9e3 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -596,10 +596,17 @@ export class ButtonBuilder extends BuilderButtonComponent { export class SelectMenuBuilder extends BuilderSelectMenuComponent { public constructor(data?: Partial); + public override addOptions( + ...options: (BuildersSelectMenuOption | SelectMenuComponentOptionData | APISelectMenuOption)[] + ): this; + public override setOptions( + ...options: (BuildersSelectMenuOption | SelectMenuComponentOptionData | APISelectMenuOption)[] + ): this; public static from(other: JSONEncodable | APISelectMenuComponent): SelectMenuBuilder; } export class SelectMenuOptionBuilder extends BuildersSelectMenuOption { + public constructor(data?: SelectMenuComponentOptionData | APISelectMenuOption); public setEmoji(emoji: ComponentEmojiResolvable): this; }