mini-interactions 0.0.0-stage → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/LICENSE +21 -0
  2. package/MIGRATION.md +126 -0
  3. package/README.md +253 -2
  4. package/dist/bot.d.ts +58 -0
  5. package/dist/bot.js +217 -0
  6. package/dist/builders/ActionRowBuilder.d.ts +22 -0
  7. package/dist/builders/ActionRowBuilder.js +33 -0
  8. package/dist/builders/AutomodRuleBuilder.d.ts +45 -0
  9. package/dist/builders/AutomodRuleBuilder.js +151 -0
  10. package/dist/builders/ButtonBuilder.d.ts +53 -0
  11. package/dist/builders/ButtonBuilder.js +124 -0
  12. package/dist/builders/ChannelSelectMenuBuilder.d.ts +53 -0
  13. package/dist/builders/ChannelSelectMenuBuilder.js +105 -0
  14. package/dist/builders/CheckboxBuilder.d.ts +20 -0
  15. package/dist/builders/CheckboxBuilder.js +20 -0
  16. package/dist/builders/CheckboxGroupBuilder.d.ts +25 -0
  17. package/dist/builders/CheckboxGroupBuilder.js +48 -0
  18. package/dist/builders/EmbedBuilder.d.ts +33 -0
  19. package/dist/builders/EmbedBuilder.js +103 -0
  20. package/dist/builders/FileUploadBuilder.d.ts +17 -0
  21. package/dist/builders/FileUploadBuilder.js +22 -0
  22. package/dist/builders/LabelBuilder.d.ts +16 -0
  23. package/dist/builders/LabelBuilder.js +21 -0
  24. package/dist/builders/MiniContainerBuilder.d.ts +131 -0
  25. package/dist/builders/MiniContainerBuilder.js +347 -0
  26. package/dist/builders/ModalBuilder.d.ts +16 -0
  27. package/dist/builders/ModalBuilder.js +36 -0
  28. package/dist/builders/ModalChannelSelectMenuBuilder.d.ts +29 -0
  29. package/dist/builders/ModalChannelSelectMenuBuilder.js +25 -0
  30. package/dist/builders/ModalMentionableSelectMenuBuilder.d.ts +53 -0
  31. package/dist/builders/ModalMentionableSelectMenuBuilder.js +87 -0
  32. package/dist/builders/ModalRoleSelectMenuBuilder.d.ts +27 -0
  33. package/dist/builders/ModalRoleSelectMenuBuilder.js +24 -0
  34. package/dist/builders/ModalStringSelectMenuBuilder.d.ts +62 -0
  35. package/dist/builders/ModalStringSelectMenuBuilder.js +120 -0
  36. package/dist/builders/ModalUserSelectMenuBuilder.d.ts +53 -0
  37. package/dist/builders/ModalUserSelectMenuBuilder.js +96 -0
  38. package/dist/builders/RadioBuilder.d.ts +22 -0
  39. package/dist/builders/RadioBuilder.js +36 -0
  40. package/dist/builders/RoleSelectMenuBuilder.d.ts +47 -0
  41. package/dist/builders/RoleSelectMenuBuilder.js +92 -0
  42. package/dist/builders/StringSelectMenuBuilder.d.ts +52 -0
  43. package/dist/builders/StringSelectMenuBuilder.js +104 -0
  44. package/dist/builders/StringSelectMenuOptionBuilder.d.ts +46 -0
  45. package/dist/builders/StringSelectMenuOptionBuilder.js +106 -0
  46. package/dist/builders/TextInputBuilder.d.ts +23 -0
  47. package/dist/builders/TextInputBuilder.js +26 -0
  48. package/dist/builders/index.d.ts +44 -0
  49. package/dist/builders/index.js +22 -0
  50. package/dist/builders/shared.d.ts +8 -0
  51. package/dist/builders/shared.js +11 -0
  52. package/dist/commands/CommandBuilder.d.ts +278 -0
  53. package/dist/commands/CommandBuilder.js +687 -0
  54. package/dist/commands/ContextMenuCommandBuilder.d.ts +94 -0
  55. package/dist/commands/ContextMenuCommandBuilder.js +145 -0
  56. package/dist/core/http/DiscordRestClient.d.ts +400 -0
  57. package/dist/core/http/DiscordRestClient.js +988 -0
  58. package/dist/core/interactions/InteractionContext.d.ts +33 -0
  59. package/dist/core/interactions/InteractionContext.js +61 -0
  60. package/dist/core/interactions/InteractionVerifier.d.ts +8 -0
  61. package/dist/core/interactions/InteractionVerifier.js +9 -0
  62. package/dist/core/messages/DiscordSentMessage.d.ts +32 -0
  63. package/dist/core/messages/DiscordSentMessage.js +64 -0
  64. package/dist/core/messages/message-payloads.d.ts +94 -0
  65. package/dist/core/messages/message-payloads.js +99 -0
  66. package/dist/core/webhooks/DiscordWebhook.d.ts +14 -0
  67. package/dist/core/webhooks/DiscordWebhook.js +69 -0
  68. package/dist/database/MiniDataBuilder.d.ts +61 -0
  69. package/dist/database/MiniDataBuilder.js +98 -0
  70. package/dist/database/MiniDatabase.d.ts +67 -0
  71. package/dist/database/MiniDatabase.js +222 -0
  72. package/dist/database/MiniDatabaseBuilder.d.ts +58 -0
  73. package/dist/database/MiniDatabaseBuilder.js +84 -0
  74. package/dist/database/index.d.ts +5 -0
  75. package/dist/database/index.js +3 -0
  76. package/dist/identity/ApplicationIdentityProfile.d.ts +188 -0
  77. package/dist/identity/ApplicationIdentityProfile.js +207 -0
  78. package/dist/index.d.ts +54 -0
  79. package/dist/index.js +34 -0
  80. package/dist/lobby/Lobby.d.ts +150 -0
  81. package/dist/lobby/Lobby.js +90 -0
  82. package/dist/node/MiniInteraction.d.ts +199 -0
  83. package/dist/node/MiniInteraction.js +861 -0
  84. package/dist/node/index.d.ts +2 -0
  85. package/dist/node/index.js +1 -0
  86. package/dist/oauth2/DiscordOAuth.d.ts +49 -0
  87. package/dist/oauth2/DiscordOAuth.js +113 -0
  88. package/dist/oauth2/OAuth2Builder.d.ts +296 -0
  89. package/dist/oauth2/OAuth2Builder.js +435 -0
  90. package/dist/oauth2/OAuth2Scopes.d.ts +285 -0
  91. package/dist/oauth2/OAuth2Scopes.js +438 -0
  92. package/dist/oauth2/OAuthTokenStorage.d.ts +37 -0
  93. package/dist/oauth2/OAuthTokenStorage.js +109 -0
  94. package/dist/oauth2/index.d.ts +8 -0
  95. package/dist/oauth2/index.js +4 -0
  96. package/dist/router/AutocompleteContext.d.ts +36 -0
  97. package/dist/router/AutocompleteContext.js +82 -0
  98. package/dist/router/InteractionRouter.d.ts +82 -0
  99. package/dist/router/InteractionRouter.js +225 -0
  100. package/dist/types/ButtonStyle.d.ts +16 -0
  101. package/dist/types/ButtonStyle.js +17 -0
  102. package/dist/types/ChannelType.d.ts +2 -0
  103. package/dist/types/ChannelType.js +2 -0
  104. package/dist/types/Commands.d.ts +35 -0
  105. package/dist/types/Commands.js +1 -0
  106. package/dist/types/ComponentTypes.d.ts +19 -0
  107. package/dist/types/ComponentTypes.js +1 -0
  108. package/dist/types/InteractionFlags.d.ts +5 -0
  109. package/dist/types/InteractionFlags.js +6 -0
  110. package/dist/types/PermissionFlags.d.ts +56 -0
  111. package/dist/types/PermissionFlags.js +5 -0
  112. package/dist/types/RoleConnectionMetadata.d.ts +14 -0
  113. package/dist/types/RoleConnectionMetadata.js +1 -0
  114. package/dist/types/RoleConnectionMetadataTypes.d.ts +11 -0
  115. package/dist/types/RoleConnectionMetadataTypes.js +12 -0
  116. package/dist/types/SeparatorSpacingSize.d.ts +2 -0
  117. package/dist/types/SeparatorSpacingSize.js +2 -0
  118. package/dist/types/checkbox.d.ts +16 -0
  119. package/dist/types/checkbox.js +12 -0
  120. package/dist/types/discord.d.ts +2 -0
  121. package/dist/types/discord.js +1 -0
  122. package/dist/types/radio.d.ts +12 -0
  123. package/dist/types/radio.js +10 -0
  124. package/dist/types/validation.d.ts +14 -0
  125. package/dist/types/validation.js +40 -0
  126. package/dist/utils/CommandInteractionOptions.d.ts +66 -0
  127. package/dist/utils/CommandInteractionOptions.js +364 -0
  128. package/dist/utils/ContextMenuInteraction.d.ts +76 -0
  129. package/dist/utils/ContextMenuInteraction.js +152 -0
  130. package/dist/utils/MessageComponentInteraction.d.ts +148 -0
  131. package/dist/utils/MessageComponentInteraction.js +259 -0
  132. package/dist/utils/ModalSubmitInteraction.d.ts +86 -0
  133. package/dist/utils/ModalSubmitInteraction.js +267 -0
  134. package/dist/utils/cdn.d.ts +30 -0
  135. package/dist/utils/cdn.js +60 -0
  136. package/dist/utils/formatting.d.ts +76 -0
  137. package/dist/utils/formatting.js +132 -0
  138. package/dist/utils/interactionMessageHelpers.d.ts +40 -0
  139. package/dist/utils/interactionMessageHelpers.js +118 -0
  140. package/dist/utils/localization.d.ts +25 -0
  141. package/dist/utils/localization.js +38 -0
  142. package/dist/utils/snowflake.d.ts +19 -0
  143. package/dist/utils/snowflake.js +32 -0
  144. package/dist/webhooks/WebhookEvent.d.ts +229 -0
  145. package/dist/webhooks/WebhookEvent.js +59 -0
  146. package/dist/webhooks/WebhookEventRouter.d.ts +123 -0
  147. package/dist/webhooks/WebhookEventRouter.js +160 -0
  148. package/dist/webhooks/WebhookEventVerifier.d.ts +33 -0
  149. package/dist/webhooks/WebhookEventVerifier.js +37 -0
  150. package/dist/webhooks/index.d.ts +6 -0
  151. package/dist/webhooks/index.js +3 -0
  152. package/package.json +90 -4
@@ -0,0 +1,62 @@
1
+ import { type APISelectMenuOption, type APIStringSelectComponent } from "discord-api-types/v10";
2
+ import type { JSONEncodable } from "./shared.js";
3
+ import type { StringSelectMenuOptionBuilder } from "./StringSelectMenuOptionBuilder.js";
4
+ /** Shape describing initial modal string select menu data accepted by the builder. */
5
+ export type ModalStringSelectMenuBuilderData = {
6
+ customId?: string;
7
+ placeholder?: string;
8
+ minValues?: number;
9
+ maxValues?: number;
10
+ disabled?: boolean;
11
+ required?: boolean;
12
+ options?: APISelectMenuOption[];
13
+ };
14
+ /** Builder for Discord string select menu components in modals. */
15
+ export declare class ModalStringSelectMenuBuilder implements JSONEncodable<APIStringSelectComponent> {
16
+ private data;
17
+ /**
18
+ * Creates a new modal string select menu builder with optional seed data.
19
+ */
20
+ constructor(data?: ModalStringSelectMenuBuilderData);
21
+ /**
22
+ * Sets the unique custom identifier for the select menu interaction.
23
+ */
24
+ setCustomId(customId: string): this;
25
+ /**
26
+ * Sets or clears the placeholder text displayed when no option is selected.
27
+ */
28
+ setPlaceholder(placeholder: string | null | undefined): this;
29
+ /**
30
+ * Sets the minimum number of options that must be selected.
31
+ */
32
+ setMinValues(minValues: number | null | undefined): this;
33
+ /**
34
+ * Sets the maximum number of options that can be selected.
35
+ */
36
+ setMaxValues(maxValues: number | null | undefined): this;
37
+ /**
38
+ * @deprecated Discord does not accept `disabled` on modal select menus; the
39
+ * value is ignored during serialisation.
40
+ */
41
+ setDisabled(disabled: boolean): this;
42
+ /**
43
+ * Marks the select menu as required in the modal.
44
+ */
45
+ setRequired(required: boolean): this;
46
+ /**
47
+ * Adds an option to the select menu.
48
+ */
49
+ addOption(option: APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>): this;
50
+ /**
51
+ * Appends new option entries to the select menu.
52
+ */
53
+ addOptions(...options: (APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>)[]): this;
54
+ /**
55
+ * Replaces all options in the select menu.
56
+ */
57
+ setOptions(options: Iterable<APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>>): this;
58
+ /**
59
+ * Serialises the builder into an API compatible string select menu payload.
60
+ */
61
+ toJSON(): APIStringSelectComponent;
62
+ }
@@ -0,0 +1,120 @@
1
+ import { ComponentType, } from "discord-api-types/v10";
2
+ import { assertSelectMenuConstraints, ValidationError } from "../types/validation.js";
3
+ /** Builder for Discord string select menu components in modals. */
4
+ export class ModalStringSelectMenuBuilder {
5
+ data;
6
+ /**
7
+ * Creates a new modal string select menu builder with optional seed data.
8
+ */
9
+ constructor(data = {}) {
10
+ this.data = {
11
+ customId: data.customId,
12
+ placeholder: data.placeholder,
13
+ minValues: data.minValues,
14
+ maxValues: data.maxValues,
15
+ disabled: data.disabled,
16
+ required: data.required,
17
+ options: data.options ? [...data.options] : [],
18
+ };
19
+ }
20
+ /**
21
+ * Sets the unique custom identifier for the select menu interaction.
22
+ */
23
+ setCustomId(customId) {
24
+ this.data.customId = customId;
25
+ return this;
26
+ }
27
+ /**
28
+ * Sets or clears the placeholder text displayed when no option is selected.
29
+ */
30
+ setPlaceholder(placeholder) {
31
+ this.data.placeholder = placeholder ?? undefined;
32
+ return this;
33
+ }
34
+ /**
35
+ * Sets the minimum number of options that must be selected.
36
+ */
37
+ setMinValues(minValues) {
38
+ this.data.minValues = minValues ?? undefined;
39
+ return this;
40
+ }
41
+ /**
42
+ * Sets the maximum number of options that can be selected.
43
+ */
44
+ setMaxValues(maxValues) {
45
+ this.data.maxValues = maxValues ?? undefined;
46
+ return this;
47
+ }
48
+ /**
49
+ * @deprecated Discord does not accept `disabled` on modal select menus; the
50
+ * value is ignored during serialisation.
51
+ */
52
+ setDisabled(disabled) {
53
+ this.data.disabled = disabled;
54
+ return this;
55
+ }
56
+ /**
57
+ * Marks the select menu as required in the modal.
58
+ */
59
+ setRequired(required) {
60
+ this.data.required = required;
61
+ return this;
62
+ }
63
+ /**
64
+ * Adds an option to the select menu.
65
+ */
66
+ addOption(option) {
67
+ if ("toJSON" in option && typeof option.toJSON === "function") {
68
+ this.data.options.push({ ...option.toJSON() });
69
+ }
70
+ else {
71
+ this.data.options.push({ ...option });
72
+ }
73
+ return this;
74
+ }
75
+ /**
76
+ * Appends new option entries to the select menu.
77
+ */
78
+ addOptions(...options) {
79
+ this.data.options.push(...options.map((option) => {
80
+ if ("toJSON" in option && typeof option.toJSON === "function") {
81
+ return { ...option.toJSON() };
82
+ }
83
+ return { ...option };
84
+ }));
85
+ return this;
86
+ }
87
+ /**
88
+ * Replaces all options in the select menu.
89
+ */
90
+ setOptions(options) {
91
+ this.data.options = Array.from(options, (option) => {
92
+ if ("toJSON" in option && typeof option.toJSON === "function") {
93
+ return { ...option.toJSON() };
94
+ }
95
+ return { ...option };
96
+ });
97
+ return this;
98
+ }
99
+ /**
100
+ * Serialises the builder into an API compatible string select menu payload.
101
+ */
102
+ toJSON() {
103
+ const customId = assertSelectMenuConstraints("ModalStringSelectMenuBuilder", this.data);
104
+ if (this.data.options.length === 0) {
105
+ throw new ValidationError("ModalStringSelectMenuBuilder", "options", "at least one option is required");
106
+ }
107
+ if (this.data.options.length > 25) {
108
+ throw new ValidationError("ModalStringSelectMenuBuilder", "options", "no more than 25 options can be provided");
109
+ }
110
+ return {
111
+ type: ComponentType.StringSelect,
112
+ custom_id: customId,
113
+ placeholder: this.data.placeholder,
114
+ min_values: this.data.minValues,
115
+ max_values: this.data.maxValues,
116
+ required: this.data.required,
117
+ options: this.data.options,
118
+ };
119
+ }
120
+ }
@@ -0,0 +1,53 @@
1
+ import { SelectMenuDefaultValueType, type APIUserSelectComponent, type APISelectMenuDefaultValue } from "discord-api-types/v10";
2
+ import type { JSONEncodable } from "./shared.js";
3
+ /** Shape describing initial modal user select menu data accepted by the builder. */
4
+ export type ModalUserSelectMenuBuilderData = {
5
+ customId?: string;
6
+ placeholder?: string;
7
+ minValues?: number;
8
+ maxValues?: number;
9
+ disabled?: boolean;
10
+ required?: boolean;
11
+ defaultValues?: APISelectMenuDefaultValue<SelectMenuDefaultValueType.User>[];
12
+ };
13
+ /** Builder for Discord user select menu components in modals. */
14
+ export declare class ModalUserSelectMenuBuilder implements JSONEncodable<APIUserSelectComponent> {
15
+ private data;
16
+ /**
17
+ * Creates a new modal user select menu builder with optional seed data.
18
+ */
19
+ constructor(data?: ModalUserSelectMenuBuilderData);
20
+ /**
21
+ * Sets the unique custom identifier for the select menu interaction.
22
+ */
23
+ setCustomId(customId: string): this;
24
+ /**
25
+ * Sets or clears the placeholder text displayed when no user is selected.
26
+ */
27
+ setPlaceholder(placeholder: string | null | undefined): this;
28
+ /**
29
+ * Sets the minimum number of users that must be selected.
30
+ */
31
+ setMinValues(minValues: number | null | undefined): this;
32
+ /**
33
+ * Sets the maximum number of users that can be selected.
34
+ */
35
+ setMaxValues(maxValues: number | null | undefined): this;
36
+ /**
37
+ * @deprecated Discord does not accept `disabled` on modal select menus; the
38
+ * value is ignored during serialisation.
39
+ */
40
+ setDisabled(disabled: boolean): this;
41
+ /**
42
+ * Marks the select menu as required in the modal.
43
+ */
44
+ setRequired(required: boolean): this;
45
+ /**
46
+ * Replaces the default user selections displayed when the menu renders.
47
+ */
48
+ setDefaultValues(defaultValues: Iterable<APISelectMenuDefaultValue<SelectMenuDefaultValueType.User>>): this;
49
+ /**
50
+ * Serialises the builder into an API compatible user select menu payload.
51
+ */
52
+ toJSON(): APIUserSelectComponent;
53
+ }
@@ -0,0 +1,96 @@
1
+ import { ComponentType, SelectMenuDefaultValueType, } from "discord-api-types/v10";
2
+ import { assertSelectMenuConstraints } from "../types/validation.js";
3
+ /** Builder for Discord user select menu components in modals. */
4
+ export class ModalUserSelectMenuBuilder {
5
+ data;
6
+ /**
7
+ * Creates a new modal user select menu builder with optional seed data.
8
+ */
9
+ constructor(data = {}) {
10
+ this.data = {
11
+ customId: data.customId,
12
+ placeholder: data.placeholder,
13
+ minValues: data.minValues,
14
+ maxValues: data.maxValues,
15
+ disabled: data.disabled,
16
+ required: data.required,
17
+ defaultValues: data.defaultValues
18
+ ? data.defaultValues.map((value) => ({
19
+ ...value,
20
+ type: SelectMenuDefaultValueType.User,
21
+ }))
22
+ : undefined,
23
+ };
24
+ }
25
+ /**
26
+ * Sets the unique custom identifier for the select menu interaction.
27
+ */
28
+ setCustomId(customId) {
29
+ this.data.customId = customId;
30
+ return this;
31
+ }
32
+ /**
33
+ * Sets or clears the placeholder text displayed when no user is selected.
34
+ */
35
+ setPlaceholder(placeholder) {
36
+ this.data.placeholder = placeholder ?? undefined;
37
+ return this;
38
+ }
39
+ /**
40
+ * Sets the minimum number of users that must be selected.
41
+ */
42
+ setMinValues(minValues) {
43
+ this.data.minValues = minValues ?? undefined;
44
+ return this;
45
+ }
46
+ /**
47
+ * Sets the maximum number of users that can be selected.
48
+ */
49
+ setMaxValues(maxValues) {
50
+ this.data.maxValues = maxValues ?? undefined;
51
+ return this;
52
+ }
53
+ /**
54
+ * @deprecated Discord does not accept `disabled` on modal select menus; the
55
+ * value is ignored during serialisation.
56
+ */
57
+ setDisabled(disabled) {
58
+ this.data.disabled = disabled;
59
+ return this;
60
+ }
61
+ /**
62
+ * Marks the select menu as required in the modal.
63
+ */
64
+ setRequired(required) {
65
+ this.data.required = required;
66
+ return this;
67
+ }
68
+ /**
69
+ * Replaces the default user selections displayed when the menu renders.
70
+ */
71
+ setDefaultValues(defaultValues) {
72
+ this.data.defaultValues = Array.from(defaultValues, (value) => ({
73
+ ...value,
74
+ type: SelectMenuDefaultValueType.User,
75
+ }));
76
+ return this;
77
+ }
78
+ /**
79
+ * Serialises the builder into an API compatible user select menu payload.
80
+ */
81
+ toJSON() {
82
+ const customId = assertSelectMenuConstraints("ModalUserSelectMenuBuilder", this.data);
83
+ return {
84
+ type: ComponentType.UserSelect,
85
+ custom_id: customId,
86
+ placeholder: this.data.placeholder,
87
+ min_values: this.data.minValues,
88
+ max_values: this.data.maxValues,
89
+ required: this.data.required,
90
+ default_values: this.data.defaultValues?.map((value) => ({
91
+ ...value,
92
+ type: SelectMenuDefaultValueType.User,
93
+ })),
94
+ };
95
+ }
96
+ }
@@ -0,0 +1,22 @@
1
+ import type { JSONEncodable } from './shared.js';
2
+ import type { APIRadioComponent, APIRadioOption } from '../types/radio.js';
3
+ export type RadioBuilderData = {
4
+ customId?: string;
5
+ required?: boolean;
6
+ options?: APIRadioOption[];
7
+ };
8
+ /**
9
+ * Builder for Discord's modal-only RadioGroup component (type 21).
10
+ * Groups hold between 2 and 10 options with at most one pre-selected default,
11
+ * and must be placed inside a Label in a modal.
12
+ *
13
+ * @see {@link https://discord.com/developers/docs/components/reference#radio-group}
14
+ */
15
+ export declare class RadioBuilder implements JSONEncodable<APIRadioComponent> {
16
+ private readonly data;
17
+ constructor(data?: RadioBuilderData);
18
+ setCustomId(customId: string): this;
19
+ setRequired(required: boolean): this;
20
+ addOptions(...options: APIRadioOption[]): this;
21
+ toJSON(): APIRadioComponent;
22
+ }
@@ -0,0 +1,36 @@
1
+ import { RADIO_COMPONENT_TYPE } from '../types/radio.js';
2
+ import { assertDefined, assertStringLength, ValidationError } from '../types/validation.js';
3
+ /**
4
+ * Builder for Discord's modal-only RadioGroup component (type 21).
5
+ * Groups hold between 2 and 10 options with at most one pre-selected default,
6
+ * and must be placed inside a Label in a modal.
7
+ *
8
+ * @see {@link https://discord.com/developers/docs/components/reference#radio-group}
9
+ */
10
+ export class RadioBuilder {
11
+ data;
12
+ constructor(data = {}) { this.data = { ...data, options: data.options ? [...data.options] : [] }; }
13
+ setCustomId(customId) { this.data.customId = customId; return this; }
14
+ setRequired(required) { this.data.required = required; return this; }
15
+ addOptions(...options) { this.data.options = [...(this.data.options ?? []), ...options]; return this; }
16
+ toJSON() {
17
+ const customId = assertDefined('RadioBuilder', 'custom_id', this.data.customId);
18
+ assertStringLength('RadioBuilder', 'custom_id', customId, 1, 100);
19
+ const options = [...(this.data.options ?? [])];
20
+ if (options.length < 2 || options.length > 10) {
21
+ throw new ValidationError('RadioBuilder', 'options', 'must contain between 2 and 10 options');
22
+ }
23
+ let defaults = 0;
24
+ for (const [index, option] of options.entries()) {
25
+ assertStringLength('RadioBuilder', `options[${index}].label`, option.label, 1, 100);
26
+ assertStringLength('RadioBuilder', `options[${index}].value`, option.value, 1, 100);
27
+ if (option.description)
28
+ assertStringLength('RadioBuilder', `options[${index}].description`, option.description, 1, 100);
29
+ if (option.default)
30
+ defaults += 1;
31
+ }
32
+ if (defaults > 1)
33
+ throw new ValidationError('RadioBuilder', 'options.default', 'radio supports only one default option');
34
+ return { type: RADIO_COMPONENT_TYPE, custom_id: customId, required: this.data.required, options };
35
+ }
36
+ }
@@ -0,0 +1,47 @@
1
+ import { SelectMenuDefaultValueType, type APIRoleSelectComponent, type APISelectMenuDefaultValue } from "discord-api-types/v10";
2
+ import type { JSONEncodable } from "./shared.js";
3
+ /** Shape describing initial role select menu data accepted by the builder. */
4
+ export type RoleSelectMenuBuilderData = {
5
+ customId?: string;
6
+ placeholder?: string;
7
+ minValues?: number;
8
+ maxValues?: number;
9
+ disabled?: boolean;
10
+ defaultValues?: APISelectMenuDefaultValue<SelectMenuDefaultValueType.Role>[];
11
+ };
12
+ /** Builder for Discord role select menu components. */
13
+ export declare class RoleSelectMenuBuilder implements JSONEncodable<APIRoleSelectComponent> {
14
+ private data;
15
+ /**
16
+ * Creates a new role select menu builder with optional seed data.
17
+ */
18
+ constructor(data?: RoleSelectMenuBuilderData);
19
+ /**
20
+ * Sets the unique custom identifier for the select menu interaction.
21
+ */
22
+ setCustomId(customId: string): this;
23
+ /**
24
+ * Sets or clears the placeholder text displayed when no role is selected.
25
+ */
26
+ setPlaceholder(placeholder: string | null | undefined): this;
27
+ /**
28
+ * Sets the minimum number of roles that must be selected.
29
+ */
30
+ setMinValues(minValues: number | null | undefined): this;
31
+ /**
32
+ * Sets the maximum number of roles that can be selected.
33
+ */
34
+ setMaxValues(maxValues: number | null | undefined): this;
35
+ /**
36
+ * Toggles whether the select menu is disabled.
37
+ */
38
+ setDisabled(disabled: boolean): this;
39
+ /**
40
+ * Replaces the default role selections displayed when the menu renders.
41
+ */
42
+ setDefaultValues(defaultValues: Iterable<APISelectMenuDefaultValue<SelectMenuDefaultValueType.Role>>): this;
43
+ /**
44
+ * Serialises the builder into an API compatible role select menu payload.
45
+ */
46
+ toJSON(): APIRoleSelectComponent;
47
+ }
@@ -0,0 +1,92 @@
1
+ import { ComponentType, SelectMenuDefaultValueType, } from "discord-api-types/v10";
2
+ /** Builder for Discord role select menu components. */
3
+ export class RoleSelectMenuBuilder {
4
+ data;
5
+ /**
6
+ * Creates a new role select menu builder with optional seed data.
7
+ */
8
+ constructor(data = {}) {
9
+ this.data = {
10
+ customId: data.customId,
11
+ placeholder: data.placeholder,
12
+ minValues: data.minValues,
13
+ maxValues: data.maxValues,
14
+ disabled: data.disabled,
15
+ defaultValues: data.defaultValues
16
+ ? data.defaultValues.map((value) => ({
17
+ ...value,
18
+ type: SelectMenuDefaultValueType.Role,
19
+ }))
20
+ : undefined,
21
+ };
22
+ }
23
+ /**
24
+ * Sets the unique custom identifier for the select menu interaction.
25
+ */
26
+ setCustomId(customId) {
27
+ this.data.customId = customId;
28
+ return this;
29
+ }
30
+ /**
31
+ * Sets or clears the placeholder text displayed when no role is selected.
32
+ */
33
+ setPlaceholder(placeholder) {
34
+ this.data.placeholder = placeholder ?? undefined;
35
+ return this;
36
+ }
37
+ /**
38
+ * Sets the minimum number of roles that must be selected.
39
+ */
40
+ setMinValues(minValues) {
41
+ this.data.minValues = minValues ?? undefined;
42
+ return this;
43
+ }
44
+ /**
45
+ * Sets the maximum number of roles that can be selected.
46
+ */
47
+ setMaxValues(maxValues) {
48
+ this.data.maxValues = maxValues ?? undefined;
49
+ return this;
50
+ }
51
+ /**
52
+ * Toggles whether the select menu is disabled.
53
+ */
54
+ setDisabled(disabled) {
55
+ this.data.disabled = disabled;
56
+ return this;
57
+ }
58
+ /**
59
+ * Replaces the default role selections displayed when the menu renders.
60
+ */
61
+ setDefaultValues(defaultValues) {
62
+ this.data.defaultValues = Array.from(defaultValues, (value) => ({
63
+ ...value,
64
+ type: SelectMenuDefaultValueType.Role,
65
+ }));
66
+ return this;
67
+ }
68
+ /**
69
+ * Serialises the builder into an API compatible role select menu payload.
70
+ */
71
+ toJSON() {
72
+ const { customId } = this.data;
73
+ if (!customId) {
74
+ throw new Error("[RoleSelectMenuBuilder] custom id is required.");
75
+ }
76
+ if (this.data.placeholder && this.data.placeholder.length > 150) {
77
+ throw new Error("[RoleSelectMenuBuilder] placeholder must be 150 characters or less.");
78
+ }
79
+ return {
80
+ type: ComponentType.RoleSelect,
81
+ custom_id: customId,
82
+ placeholder: this.data.placeholder,
83
+ min_values: this.data.minValues,
84
+ max_values: this.data.maxValues,
85
+ disabled: this.data.disabled,
86
+ default_values: this.data.defaultValues?.map((value) => ({
87
+ ...value,
88
+ type: SelectMenuDefaultValueType.Role,
89
+ })),
90
+ };
91
+ }
92
+ }
@@ -0,0 +1,52 @@
1
+ import { type APISelectMenuOption, type APIStringSelectComponent } from "discord-api-types/v10";
2
+ import type { JSONEncodable } from "./shared.js";
3
+ import type { StringSelectMenuOptionBuilder } from "./StringSelectMenuOptionBuilder.js";
4
+ /** Shape describing initial string select menu data accepted by the builder. */
5
+ export type StringSelectMenuBuilderData = {
6
+ customId?: string;
7
+ placeholder?: string;
8
+ minValues?: number;
9
+ maxValues?: number;
10
+ disabled?: boolean;
11
+ options?: APISelectMenuOption[];
12
+ };
13
+ /** Builder for Discord string select menu components. */
14
+ export declare class StringSelectMenuBuilder implements JSONEncodable<APIStringSelectComponent> {
15
+ private data;
16
+ /**
17
+ * Creates a new string select menu builder with optional seed data.
18
+ */
19
+ constructor(data?: StringSelectMenuBuilderData);
20
+ /**
21
+ * Sets the unique custom identifier for the select menu interaction.
22
+ */
23
+ setCustomId(customId: string): this;
24
+ /**
25
+ * Sets or clears the placeholder text displayed when no option is selected.
26
+ */
27
+ setPlaceholder(placeholder: string | null | undefined): this;
28
+ /**
29
+ * Sets the minimum number of options that must be selected.
30
+ */
31
+ setMinValues(minValues: number | null | undefined): this;
32
+ /**
33
+ * Sets the maximum number of options that can be selected.
34
+ */
35
+ setMaxValues(maxValues: number | null | undefined): this;
36
+ /**
37
+ * Toggles whether the select menu is disabled.
38
+ */
39
+ setDisabled(disabled: boolean): this;
40
+ /**
41
+ * Appends new option entries to the select menu.
42
+ */
43
+ addOptions(...options: (APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>)[]): this;
44
+ /**
45
+ * Replaces the current option set with the provided iterable.
46
+ */
47
+ setOptions(options: Iterable<APISelectMenuOption | StringSelectMenuOptionBuilder | JSONEncodable<APISelectMenuOption>>): this;
48
+ /**
49
+ * Serialises the builder into an API compatible string select menu payload.
50
+ */
51
+ toJSON(): APIStringSelectComponent;
52
+ }
@@ -0,0 +1,104 @@
1
+ import { ComponentType, } from "discord-api-types/v10";
2
+ /** Builder for Discord string select menu components. */
3
+ export class StringSelectMenuBuilder {
4
+ data;
5
+ /**
6
+ * Creates a new string select menu builder with optional seed data.
7
+ */
8
+ constructor(data = {}) {
9
+ this.data = {
10
+ customId: data.customId,
11
+ placeholder: data.placeholder,
12
+ minValues: data.minValues,
13
+ maxValues: data.maxValues,
14
+ disabled: data.disabled,
15
+ options: data.options ? [...data.options] : [],
16
+ };
17
+ }
18
+ /**
19
+ * Sets the unique custom identifier for the select menu interaction.
20
+ */
21
+ setCustomId(customId) {
22
+ this.data.customId = customId;
23
+ return this;
24
+ }
25
+ /**
26
+ * Sets or clears the placeholder text displayed when no option is selected.
27
+ */
28
+ setPlaceholder(placeholder) {
29
+ this.data.placeholder = placeholder ?? undefined;
30
+ return this;
31
+ }
32
+ /**
33
+ * Sets the minimum number of options that must be selected.
34
+ */
35
+ setMinValues(minValues) {
36
+ this.data.minValues = minValues ?? undefined;
37
+ return this;
38
+ }
39
+ /**
40
+ * Sets the maximum number of options that can be selected.
41
+ */
42
+ setMaxValues(maxValues) {
43
+ this.data.maxValues = maxValues ?? undefined;
44
+ return this;
45
+ }
46
+ /**
47
+ * Toggles whether the select menu is disabled.
48
+ */
49
+ setDisabled(disabled) {
50
+ this.data.disabled = disabled;
51
+ return this;
52
+ }
53
+ /**
54
+ * Appends new option entries to the select menu.
55
+ */
56
+ addOptions(...options) {
57
+ this.data.options.push(...options.map((option) => {
58
+ if ("toJSON" in option && typeof option.toJSON === "function") {
59
+ return { ...option.toJSON() };
60
+ }
61
+ return { ...option };
62
+ }));
63
+ return this;
64
+ }
65
+ /**
66
+ * Replaces the current option set with the provided iterable.
67
+ */
68
+ setOptions(options) {
69
+ this.data.options = Array.from(options, (option) => {
70
+ if ("toJSON" in option && typeof option.toJSON === "function") {
71
+ return { ...option.toJSON() };
72
+ }
73
+ return { ...option };
74
+ });
75
+ return this;
76
+ }
77
+ /**
78
+ * Serialises the builder into an API compatible string select menu payload.
79
+ */
80
+ toJSON() {
81
+ const { customId, options } = this.data;
82
+ if (!customId) {
83
+ throw new Error("[StringSelectMenuBuilder] custom id is required.");
84
+ }
85
+ if (this.data.placeholder && this.data.placeholder.length > 150) {
86
+ throw new Error("[StringSelectMenuBuilder] placeholder must be 150 characters or less.");
87
+ }
88
+ if (options.length === 0) {
89
+ throw new Error("[StringSelectMenuBuilder] at least one option is required.");
90
+ }
91
+ if (options.length > 25) {
92
+ throw new Error("[StringSelectMenuBuilder] no more than 25 options can be provided.");
93
+ }
94
+ return {
95
+ type: ComponentType.StringSelect,
96
+ custom_id: customId,
97
+ placeholder: this.data.placeholder,
98
+ min_values: this.data.minValues,
99
+ max_values: this.data.maxValues,
100
+ disabled: this.data.disabled,
101
+ options: options.map((option) => ({ ...option })),
102
+ };
103
+ }
104
+ }