fix: mentionables defaults (#162)

This commit is contained in:
Marcos Susaña 2024-03-27 15:58:03 -04:00 committed by GitHub
parent b46c16cd50
commit 52d8501d55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -177,6 +177,8 @@ export class RoleSelectMenu extends SelectMenu<APIRoleSelectComponent, RoleSelec
}
}
export type MentionableDefaultElement = { id: string; type: keyof Omit<typeof SelectMenuDefaultValueType, 'Channel'> };
/**
* Represents a Select Menu for selecting mentionable entities.
* @example
@ -187,6 +189,34 @@ export class MentionableSelectMenu extends SelectMenu<APIMentionableSelectCompon
constructor(data: Partial<APIMentionableSelectComponent> = {}) {
super({ ...data, type: ComponentType.MentionableSelect });
}
/**
* Sets the default selected roles or users for the select menu.
* @param mentionables - Role/User id and type to be set as default.
* @returns The current MentionableSelectMenu instance.
*/
setDefaults(...mentionables: RestOrArray<MentionableDefaultElement>) {
this.data.default_values = mentionables.flat().map(mentionable => ({
id: mentionable.id,
type: SelectMenuDefaultValueType[mentionable.type],
}));
return this;
}
/**
* Adds default selected roles or users for the select menu.
* @param mentionables - Role/User id and type to be added as default.
* @returns The current MentionableSelectMenu instance.
*/
addDefaultMentionables(...mentionables: RestOrArray<MentionableDefaultElement>) {
this.data.default_values = (this.data.default_values ?? []).concat(
mentionables.flat().map(mentionable => ({
id: mentionable.id,
type: SelectMenuDefaultValueType[mentionable.type],
})),
);
return this;
}
}
/**