mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 21:13:30 +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
|
* Adds options to this select menu
|
||||||
* @param {RestOrArray<APISelectMenuOption>} options The options to add to this select menu
|
* @param {RestOrArray<APISelectMenuOption>} options The options to add to this select menu
|
||||||
* @returns {SelectMenuBuilder}
|
* @returns {SelectMenuBuilder}
|
||||||
*/
|
*/
|
||||||
addOptions(...options) {
|
addOptions(...options) {
|
||||||
return super.addOptions(
|
return super.addOptions(normalizeArray(options).map(option => SelectMenuBuilder.normalizeEmoji(option)));
|
||||||
normalizeArray(options).map(({ emoji, ...option }) => ({
|
|
||||||
...option,
|
|
||||||
emoji: emoji && typeof emoji === 'string' ? parseEmoji(emoji) : emoji,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,12 +54,7 @@ class SelectMenuBuilder extends BuildersSelectMenu {
|
|||||||
* @returns {SelectMenuBuilder}
|
* @returns {SelectMenuBuilder}
|
||||||
*/
|
*/
|
||||||
setOptions(...options) {
|
setOptions(...options) {
|
||||||
return super.setOptions(
|
return super.setOptions(normalizeArray(options).map(option => SelectMenuBuilder.normalizeEmoji(option)));
|
||||||
normalizeArray(options).map(({ emoji, ...option }) => ({
|
|
||||||
...option,
|
|
||||||
emoji: emoji && typeof emoji === 'string' ? parseEmoji(emoji) : emoji,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
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 {
|
export class SelectMenuBuilder extends BuilderSelectMenuComponent {
|
||||||
public constructor(data?: Partial<SelectMenuComponentData | APISelectMenuComponent>);
|
public constructor(data?: Partial<SelectMenuComponentData | APISelectMenuComponent>);
|
||||||
|
private static normalizeEmoji(
|
||||||
|
selectMenuOption: JSONEncodable<APISelectMenuOption> | SelectMenuComponentOptionData,
|
||||||
|
): (APISelectMenuOption | SelectMenuOptionBuilder)[];
|
||||||
public override addOptions(
|
public override addOptions(
|
||||||
...options: RestOrArray<BuildersSelectMenuOption | SelectMenuComponentOptionData | APISelectMenuOption>
|
...options: RestOrArray<BuildersSelectMenuOption | SelectMenuComponentOptionData | APISelectMenuOption>
|
||||||
): this;
|
): this;
|
||||||
|
|||||||
Reference in New Issue
Block a user