mirror of
https://github.com/discordjs/discord.js.git
synced 2026-06-03 09:30:08 +00:00
feat: default select menu values (#9867)
* feat: default select menu values * feat(Message): support * fix: fix crashes when an array is supplied and remove assertion * docs(transformResolved): `BaseChannel` is the correct type * refactor: prefer assignment * chore: export function again * fix(Util): fix circular dependency * refactor(MentionableSelectMenu): clone in method * docs: remove semicolon * feat(MentionableSelectMenu): add `addDefaultValues()` * refactor: reduce overhead * types: adjust `channel` --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import type { APIChannelSelectComponent, ChannelType } from 'discord-api-types/v10';
|
||||
import { ComponentType } from 'discord-api-types/v10';
|
||||
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
|
||||
import { channelTypesValidator, customIdValidator } from '../Assertions.js';
|
||||
import {
|
||||
type APIChannelSelectComponent,
|
||||
type ChannelType,
|
||||
type Snowflake,
|
||||
ComponentType,
|
||||
SelectMenuDefaultValueType,
|
||||
} from 'discord-api-types/v10';
|
||||
import { type RestOrArray, normalizeArray } from '../../util/normalizeArray.js';
|
||||
import { channelTypesValidator, customIdValidator, optionsLengthValidator } from '../Assertions.js';
|
||||
import { BaseSelectMenuBuilder } from './BaseSelectMenu.js';
|
||||
|
||||
/**
|
||||
@@ -59,6 +64,43 @@ export class ChannelSelectMenuBuilder extends BaseSelectMenuBuilder<APIChannelSe
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds default channels to this auto populated select menu.
|
||||
*
|
||||
* @param channels - The channels to add
|
||||
*/
|
||||
public addDefaultChannels(...channels: RestOrArray<Snowflake>) {
|
||||
const normalizedValues = normalizeArray(channels);
|
||||
optionsLengthValidator.parse((this.data.default_values?.length ?? 0) + normalizedValues.length);
|
||||
this.data.default_values ??= [];
|
||||
|
||||
this.data.default_values.push(
|
||||
...normalizedValues.map((id) => ({
|
||||
id,
|
||||
type: SelectMenuDefaultValueType.Channel as const,
|
||||
})),
|
||||
);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default channels to this auto populated select menu.
|
||||
*
|
||||
* @param channels - The channels to set
|
||||
*/
|
||||
public setDefaultChannels(...channels: RestOrArray<Snowflake>) {
|
||||
const normalizedValues = normalizeArray(channels);
|
||||
optionsLengthValidator.parse(normalizedValues.length);
|
||||
|
||||
this.data.default_values = normalizedValues.map((id) => ({
|
||||
id,
|
||||
type: SelectMenuDefaultValueType.Channel as const,
|
||||
}));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc BaseSelectMenuBuilder.toJSON}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user