diff --git a/packages/builders/src/components/selectMenu/ChannelSelectMenu.ts b/packages/builders/src/components/selectMenu/ChannelSelectMenu.ts index 56fb25d423e29..0a0a3ecc0aaf0 100644 --- a/packages/builders/src/components/selectMenu/ChannelSelectMenu.ts +++ b/packages/builders/src/components/selectMenu/ChannelSelectMenu.ts @@ -1,11 +1,11 @@ -import type { - APIChannelSelectComponent, - APISelectMenuDefaultValue, - ChannelType, - Snowflake, +import { + type APIChannelSelectComponent, + type ChannelType, + type Snowflake, + ComponentType, + SelectMenuDefaultValueType, } from 'discord-api-types/v10'; -import { ComponentType, SelectMenuDefaultValueType } from 'discord-api-types/v10'; -import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js'; +import { type RestOrArray, normalizeArray } from '../../util/normalizeArray.js'; import { channelTypesValidator, customIdValidator, optionsLengthValidator } from '../Assertions.js'; import { BaseSelectMenuBuilder } from './BaseSelectMenu.js'; @@ -70,9 +70,11 @@ export class ChannelSelectMenuBuilder extends BaseSelectMenuBuilder) { - const normalizedValues = channels.map((id) => { - return { id, type: SelectMenuDefaultValueType.Channel }; - }) as APISelectMenuDefaultValue[]; + const normalizedValues = normalizeArray(channels).map((id) => ({ + id, + type: SelectMenuDefaultValueType.Channel as const, + })); + this.data.default_values ??= []; optionsLengthValidator.parse(this.data.default_values.length + normalizedValues.length); this.data.default_values.push(...normalizedValues); @@ -85,9 +87,11 @@ export class ChannelSelectMenuBuilder extends BaseSelectMenuBuilder) { - const normalizedValues = channels.map((id) => { - return { id, type: SelectMenuDefaultValueType.Channel }; - }) as APISelectMenuDefaultValue[]; + const normalizedValues = normalizeArray(channels).map((id) => ({ + id, + type: SelectMenuDefaultValueType.Channel as const, + })); + optionsLengthValidator.parse(normalizedValues.length); this.data.default_values ??= []; this.data.default_values.splice(0, this.data.default_values.length, ...normalizedValues); diff --git a/packages/builders/src/components/selectMenu/MentionableSelectMenu.ts b/packages/builders/src/components/selectMenu/MentionableSelectMenu.ts index f90ad443bc5b1..1f0b3736c7b84 100644 --- a/packages/builders/src/components/selectMenu/MentionableSelectMenu.ts +++ b/packages/builders/src/components/selectMenu/MentionableSelectMenu.ts @@ -1,7 +1,11 @@ -import type { APIMentionableSelectComponent, APISelectMenuDefaultValue, Snowflake } from 'discord-api-types/v10'; -import { ComponentType, SelectMenuDefaultValueType } from 'discord-api-types/v10'; -import type { RestOrArray } from '../../index.js'; -import { normalizeArray } from '../../index.js'; +import { + type APIMentionableSelectComponent, + type APISelectMenuDefaultValue, + type Snowflake, + ComponentType, + SelectMenuDefaultValueType, +} from 'discord-api-types/v10'; +import { type RestOrArray, normalizeArray } from '../../util/normalizeArray.js'; import { optionsLengthValidator } from '../Assertions.js'; import { BaseSelectMenuBuilder } from './BaseSelectMenu.js'; @@ -41,9 +45,11 @@ export class MentionableSelectMenuBuilder extends BaseSelectMenuBuilder) { - const normalizedValues = roles.map((id) => { - return { id, type: SelectMenuDefaultValueType.Role }; - }) as APISelectMenuDefaultValue[]; + const normalizedValues = normalizeArray(roles).map((id) => ({ + id, + type: SelectMenuDefaultValueType.Role as const, + })); + this.data.default_values ??= []; optionsLengthValidator.parse(this.data.default_values.length + normalizedValues.length); this.data.default_values.push(...normalizedValues); @@ -56,9 +62,11 @@ export class MentionableSelectMenuBuilder extends BaseSelectMenuBuilder) { - const normalizedValues = users.map((id) => { - return { id, type: SelectMenuDefaultValueType.User }; - }) as APISelectMenuDefaultValue[]; + const normalizedValues = normalizeArray(users).map((id) => ({ + id, + type: SelectMenuDefaultValueType.User as const, + })); + this.data.default_values ??= []; optionsLengthValidator.parse(this.data.default_values.length + normalizedValues.length); this.data.default_values.push(...normalizedValues); diff --git a/packages/builders/src/components/selectMenu/RoleSelectMenu.ts b/packages/builders/src/components/selectMenu/RoleSelectMenu.ts index 658e76d058072..271bc09bab00e 100644 --- a/packages/builders/src/components/selectMenu/RoleSelectMenu.ts +++ b/packages/builders/src/components/selectMenu/RoleSelectMenu.ts @@ -1,6 +1,10 @@ -import type { APIRoleSelectComponent, APISelectMenuDefaultValue, Snowflake } from 'discord-api-types/v10'; -import { ComponentType, SelectMenuDefaultValueType } from 'discord-api-types/v10'; -import type { RestOrArray } from '../../index.js'; +import { + type APIRoleSelectComponent, + type Snowflake, + ComponentType, + SelectMenuDefaultValueType, +} from 'discord-api-types/v10'; +import { type RestOrArray, normalizeArray } from '../../util/normalizeArray.js'; import { optionsLengthValidator } from '../Assertions.js'; import { BaseSelectMenuBuilder } from './BaseSelectMenu.js'; @@ -40,9 +44,11 @@ export class RoleSelectMenuBuilder extends BaseSelectMenuBuilder) { - const normalizedValues = roles.map((id) => { - return { id, type: SelectMenuDefaultValueType.Role }; - }) as APISelectMenuDefaultValue[]; + const normalizedValues = normalizeArray(roles).map((id) => ({ + id, + type: SelectMenuDefaultValueType.Role as const, + })); + this.data.default_values ??= []; optionsLengthValidator.parse(this.data.default_values.length + normalizedValues.length); this.data.default_values.push(...normalizedValues); @@ -55,9 +61,11 @@ export class RoleSelectMenuBuilder extends BaseSelectMenuBuilder) { - const normalizedValues = roles.map((id) => { - return { id, type: SelectMenuDefaultValueType.Role }; - }) as APISelectMenuDefaultValue[]; + const normalizedValues = normalizeArray(roles).map((id) => ({ + id, + type: SelectMenuDefaultValueType.Role as const, + })); + optionsLengthValidator.parse(normalizedValues.length); this.data.default_values ??= []; this.data.default_values.splice(0, this.data.default_values.length, ...normalizedValues); diff --git a/packages/builders/src/components/selectMenu/UserSelectMenu.ts b/packages/builders/src/components/selectMenu/UserSelectMenu.ts index 8d12c909e8471..cb1fa41450714 100644 --- a/packages/builders/src/components/selectMenu/UserSelectMenu.ts +++ b/packages/builders/src/components/selectMenu/UserSelectMenu.ts @@ -1,6 +1,10 @@ -import type { APISelectMenuDefaultValue, APIUserSelectComponent, Snowflake } from 'discord-api-types/v10'; -import { ComponentType, SelectMenuDefaultValueType } from 'discord-api-types/v10'; -import type { RestOrArray } from '../../index.js'; +import { + type APIUserSelectComponent, + type Snowflake, + ComponentType, + SelectMenuDefaultValueType, +} from 'discord-api-types/v10'; +import { type RestOrArray, normalizeArray } from '../../util/normalizeArray.js'; import { optionsLengthValidator } from '../Assertions.js'; import { BaseSelectMenuBuilder } from './BaseSelectMenu.js'; @@ -40,9 +44,10 @@ export class UserSelectMenuBuilder extends BaseSelectMenuBuilder) { - const normalizedValues = users.map((id) => { - return { id, type: SelectMenuDefaultValueType.User }; - }) as APISelectMenuDefaultValue[]; + const normalizedValues = normalizeArray(users).map((id) => ({ + id, + type: SelectMenuDefaultValueType.User as const, + })); this.data.default_values ??= []; optionsLengthValidator.parse(this.data.default_values.length + normalizedValues.length); this.data.default_values.push(...normalizedValues); @@ -55,9 +60,10 @@ export class UserSelectMenuBuilder extends BaseSelectMenuBuilder) { - const normalizedValues = users.map((id) => { - return { id, type: SelectMenuDefaultValueType.User }; - }) as APISelectMenuDefaultValue[]; + const normalizedValues = normalizeArray(users).map((id) => ({ + id, + type: SelectMenuDefaultValueType.User as const, + })); optionsLengthValidator.parse(normalizedValues.length); this.data.default_values ??= []; this.data.default_values.splice(0, this.data.default_values.length, ...normalizedValues);