mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
fix(SelectMenuBuilder): properly accept SelectMenuOptionBuilders (#8174)
This commit is contained in:
@@ -21,18 +21,31 @@ class SelectMenuBuilder extends BuildersSelectMenu {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a select menu option emoji
|
||||
* @param {SelectMenuOptionData|JSONEncodable<APISelectMenuOption>} selectMenuOption The option to normalize
|
||||
* @returns {Array<SelectMenuOptionBuilder|APISelectMenuOption>}
|
||||
* @private
|
||||
*/
|
||||
static normalizeEmoji(selectMenuOption) {
|
||||
if (isJSONEncodable(selectMenuOption)) {
|
||||
return selectMenuOption;
|
||||
}
|
||||
|
||||
const { emoji, ...option } = selectMenuOption;
|
||||
return {
|
||||
...option,
|
||||
emoji: typeof emoji === 'string' ? parseEmoji(emoji) : emoji,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds options to this select menu
|
||||
* @param {RestOrArray<APISelectMenuOption>} options The options to add to this select menu
|
||||
* @returns {SelectMenuBuilder}
|
||||
*/
|
||||
addOptions(...options) {
|
||||
return super.addOptions(
|
||||
normalizeArray(options).map(({ emoji, ...option }) => ({
|
||||
...option,
|
||||
emoji: emoji && typeof emoji === 'string' ? parseEmoji(emoji) : emoji,
|
||||
})),
|
||||
);
|
||||
return super.addOptions(normalizeArray(options).map(option => SelectMenuBuilder.normalizeEmoji(option)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,12 +54,7 @@ class SelectMenuBuilder extends BuildersSelectMenu {
|
||||
* @returns {SelectMenuBuilder}
|
||||
*/
|
||||
setOptions(...options) {
|
||||
return super.setOptions(
|
||||
normalizeArray(options).map(({ emoji, ...option }) => ({
|
||||
...option,
|
||||
emoji: emoji && typeof emoji === 'string' ? parseEmoji(emoji) : emoji,
|
||||
})),
|
||||
);
|
||||
return super.setOptions(normalizeArray(options).map(option => SelectMenuBuilder.normalizeEmoji(option)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
3
packages/discord.js/typings/index.d.ts
vendored
3
packages/discord.js/typings/index.d.ts
vendored
@@ -616,6 +616,9 @@ export class ButtonBuilder extends BuilderButtonComponent {
|
||||
|
||||
export class SelectMenuBuilder extends BuilderSelectMenuComponent {
|
||||
public constructor(data?: Partial<SelectMenuComponentData | APISelectMenuComponent>);
|
||||
private static normalizeEmoji(
|
||||
selectMenuOption: JSONEncodable<APISelectMenuOption> | SelectMenuComponentOptionData,
|
||||
): (APISelectMenuOption | SelectMenuOptionBuilder)[];
|
||||
public override addOptions(
|
||||
...options: RestOrArray<BuildersSelectMenuOption | SelectMenuComponentOptionData | APISelectMenuOption>
|
||||
): this;
|
||||
|
||||
Reference in New Issue
Block a user