@minesa-org/mini-interaction 0.0.1
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.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/builders/ActionRowBuilder.d.ts +25 -0
- package/dist/builders/ActionRowBuilder.js +35 -0
- package/dist/builders/ButtonBuilder.d.ts +53 -0
- package/dist/builders/ButtonBuilder.js +124 -0
- package/dist/builders/ChannelSelectMenuBuilder.d.ts +58 -0
- package/dist/builders/ChannelSelectMenuBuilder.js +111 -0
- package/dist/builders/ModalBuilder.d.ts +40 -0
- package/dist/builders/ModalBuilder.js +65 -0
- package/dist/builders/RoleSelectMenuBuilder.d.ts +52 -0
- package/dist/builders/RoleSelectMenuBuilder.js +98 -0
- package/dist/builders/StringSelectMenuBuilder.d.ts +56 -0
- package/dist/builders/StringSelectMenuBuilder.js +100 -0
- package/dist/builders/index.d.ts +14 -0
- package/dist/builders/index.js +7 -0
- package/dist/builders/shared.d.ts +8 -0
- package/dist/builders/shared.js +11 -0
- package/dist/clients/MiniInteraction.d.ts +176 -0
- package/dist/clients/MiniInteraction.js +578 -0
- package/dist/commands/CommandBuilder.d.ts +278 -0
- package/dist/commands/CommandBuilder.js +687 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +9 -0
- package/dist/types/ButtonStyle.d.ts +16 -0
- package/dist/types/ButtonStyle.js +17 -0
- package/dist/types/ChannelType.d.ts +2 -0
- package/dist/types/ChannelType.js +2 -0
- package/dist/types/Commands.d.ts +11 -0
- package/dist/types/Commands.js +1 -0
- package/dist/types/ComponentTypes.d.ts +5 -0
- package/dist/types/ComponentTypes.js +1 -0
- package/dist/types/InteractionFlags.d.ts +10 -0
- package/dist/types/InteractionFlags.js +12 -0
- package/dist/types/RoleConnectionMetadataTypes.d.ts +11 -0
- package/dist/types/RoleConnectionMetadataTypes.js +12 -0
- package/dist/utils/CommandInteractionOptions.d.ts +143 -0
- package/dist/utils/CommandInteractionOptions.js +376 -0
- package/dist/utils/MessageComponentInteraction.d.ts +19 -0
- package/dist/utils/MessageComponentInteraction.js +60 -0
- package/dist/utils/constants.d.ts +16 -0
- package/dist/utils/constants.js +16 -0
- package/dist/utils/interactionMessageHelpers.d.ts +30 -0
- package/dist/utils/interactionMessageHelpers.js +32 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Minesa™
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { APIActionRowComponent } from "discord-api-types/v10";
|
|
2
|
+
import type { JSONEncodable } from "./shared.js";
|
|
3
|
+
import type { MiniComponentActionRow } from "../types/ComponentTypes.js";
|
|
4
|
+
/** Values accepted when composing component action rows. */
|
|
5
|
+
export type ActionRowComponentLike<T extends MiniComponentActionRow> = JSONEncodable<T> | T;
|
|
6
|
+
/** Builder for Discord action row components. */
|
|
7
|
+
export declare class ActionRowBuilder<T extends MiniComponentActionRow = MiniComponentActionRow> implements JSONEncodable<APIActionRowComponent<T>> {
|
|
8
|
+
private components;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new action row builder with optional seed components.
|
|
11
|
+
*/
|
|
12
|
+
constructor(components?: Iterable<ActionRowComponentLike<T>>);
|
|
13
|
+
/**
|
|
14
|
+
* Appends additional components to the action row.
|
|
15
|
+
*/
|
|
16
|
+
addComponents(...components: ActionRowComponentLike<T>[]): this;
|
|
17
|
+
/**
|
|
18
|
+
* Replaces the current action row contents.
|
|
19
|
+
*/
|
|
20
|
+
setComponents(components: Iterable<ActionRowComponentLike<T>>): this;
|
|
21
|
+
/**
|
|
22
|
+
* Serialises the builder into an API compatible action row payload.
|
|
23
|
+
*/
|
|
24
|
+
toJSON(): APIActionRowComponent<T>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ComponentType } from "discord-api-types/v10";
|
|
2
|
+
import { resolveJSONEncodable } from "./shared.js";
|
|
3
|
+
/** Builder for Discord action row components. */
|
|
4
|
+
export class ActionRowBuilder {
|
|
5
|
+
components;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new action row builder with optional seed components.
|
|
8
|
+
*/
|
|
9
|
+
constructor(components = []) {
|
|
10
|
+
this.components = Array.from(components);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Appends additional components to the action row.
|
|
14
|
+
*/
|
|
15
|
+
addComponents(...components) {
|
|
16
|
+
this.components.push(...components);
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Replaces the current action row contents.
|
|
21
|
+
*/
|
|
22
|
+
setComponents(components) {
|
|
23
|
+
this.components = Array.from(components);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Serialises the builder into an API compatible action row payload.
|
|
28
|
+
*/
|
|
29
|
+
toJSON() {
|
|
30
|
+
return {
|
|
31
|
+
type: ComponentType.ActionRow,
|
|
32
|
+
components: this.components.map((component) => resolveJSONEncodable(component)),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type APIButtonComponent, type APIMessageComponentEmoji } from "discord-api-types/v10";
|
|
2
|
+
import type { JSONEncodable } from "./shared.js";
|
|
3
|
+
import { ButtonStyle } from "../types/ButtonStyle.js";
|
|
4
|
+
/** Shape describing initial button data accepted by the builder. */
|
|
5
|
+
export type ButtonBuilderData = {
|
|
6
|
+
style?: ButtonStyle;
|
|
7
|
+
label?: string;
|
|
8
|
+
emoji?: APIMessageComponentEmoji;
|
|
9
|
+
customId?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
skuId?: string;
|
|
13
|
+
};
|
|
14
|
+
/** Builder for Discord button components. */
|
|
15
|
+
export declare class ButtonBuilder implements JSONEncodable<APIButtonComponent> {
|
|
16
|
+
private data;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new button builder with optional seed data.
|
|
19
|
+
*/
|
|
20
|
+
constructor(data?: ButtonBuilderData);
|
|
21
|
+
/**
|
|
22
|
+
* Sets the visual style of the button.
|
|
23
|
+
*/
|
|
24
|
+
setStyle(style: ButtonStyle): this;
|
|
25
|
+
/**
|
|
26
|
+
* Sets or clears the button label text.
|
|
27
|
+
*/
|
|
28
|
+
setLabel(label: string | null | undefined): this;
|
|
29
|
+
/**
|
|
30
|
+
* Sets or clears the emoji displayed on the button.
|
|
31
|
+
*/
|
|
32
|
+
setEmoji(emoji: APIMessageComponentEmoji | null | undefined): this;
|
|
33
|
+
/**
|
|
34
|
+
* Configures the button as an interaction component with the provided custom identifier.
|
|
35
|
+
*/
|
|
36
|
+
setCustomId(customId: string): this;
|
|
37
|
+
/**
|
|
38
|
+
* Configures the button as a link button.
|
|
39
|
+
*/
|
|
40
|
+
setURL(url: string): this;
|
|
41
|
+
/**
|
|
42
|
+
* Configures the button as a premium purchase button.
|
|
43
|
+
*/
|
|
44
|
+
setSKUId(skuId: string): this;
|
|
45
|
+
/**
|
|
46
|
+
* Toggles whether the button is disabled.
|
|
47
|
+
*/
|
|
48
|
+
setDisabled(disabled: boolean): this;
|
|
49
|
+
/**
|
|
50
|
+
* Serialises the builder into an API compatible button payload.
|
|
51
|
+
*/
|
|
52
|
+
toJSON(): APIButtonComponent;
|
|
53
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { ComponentType, } from "discord-api-types/v10";
|
|
2
|
+
import { ButtonStyle } from "../types/ButtonStyle.js";
|
|
3
|
+
/** Builder for Discord button components. */
|
|
4
|
+
export class ButtonBuilder {
|
|
5
|
+
data;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new button builder with optional seed data.
|
|
8
|
+
*/
|
|
9
|
+
constructor(data = {}) {
|
|
10
|
+
this.data = {
|
|
11
|
+
style: data.style ?? ButtonStyle.Secondary,
|
|
12
|
+
label: data.label,
|
|
13
|
+
emoji: data.emoji ? { ...data.emoji } : undefined,
|
|
14
|
+
customId: data.customId,
|
|
15
|
+
url: data.url,
|
|
16
|
+
disabled: data.disabled,
|
|
17
|
+
skuId: data.skuId,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sets the visual style of the button.
|
|
22
|
+
*/
|
|
23
|
+
setStyle(style) {
|
|
24
|
+
this.data.style = style;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Sets or clears the button label text.
|
|
29
|
+
*/
|
|
30
|
+
setLabel(label) {
|
|
31
|
+
this.data.label = label ?? undefined;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sets or clears the emoji displayed on the button.
|
|
36
|
+
*/
|
|
37
|
+
setEmoji(emoji) {
|
|
38
|
+
this.data.emoji = emoji ? { ...emoji } : undefined;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Configures the button as an interaction component with the provided custom identifier.
|
|
43
|
+
*/
|
|
44
|
+
setCustomId(customId) {
|
|
45
|
+
this.data.customId = customId;
|
|
46
|
+
if (this.data.style === ButtonStyle.Link) {
|
|
47
|
+
this.data.style = ButtonStyle.Secondary;
|
|
48
|
+
}
|
|
49
|
+
this.data.url = undefined;
|
|
50
|
+
this.data.skuId = undefined;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Configures the button as a link button.
|
|
55
|
+
*/
|
|
56
|
+
setURL(url) {
|
|
57
|
+
this.data.url = url;
|
|
58
|
+
this.data.customId = undefined;
|
|
59
|
+
this.data.skuId = undefined;
|
|
60
|
+
this.data.style = ButtonStyle.Link;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Configures the button as a premium purchase button.
|
|
65
|
+
*/
|
|
66
|
+
setSKUId(skuId) {
|
|
67
|
+
this.data.skuId = skuId;
|
|
68
|
+
this.data.customId = undefined;
|
|
69
|
+
this.data.url = undefined;
|
|
70
|
+
this.data.style = ButtonStyle.Premium;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Toggles whether the button is disabled.
|
|
75
|
+
*/
|
|
76
|
+
setDisabled(disabled) {
|
|
77
|
+
this.data.disabled = disabled;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Serialises the builder into an API compatible button payload.
|
|
82
|
+
*/
|
|
83
|
+
toJSON() {
|
|
84
|
+
const { style, label, emoji, disabled } = this.data;
|
|
85
|
+
if (style === ButtonStyle.Link) {
|
|
86
|
+
const url = this.data.url;
|
|
87
|
+
if (!url) {
|
|
88
|
+
throw new Error("[ButtonBuilder] Link buttons must have a URL.");
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
type: ComponentType.Button,
|
|
92
|
+
style,
|
|
93
|
+
label,
|
|
94
|
+
emoji: emoji ? { ...emoji } : undefined,
|
|
95
|
+
disabled,
|
|
96
|
+
url,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (style === ButtonStyle.Premium) {
|
|
100
|
+
const skuId = this.data.skuId;
|
|
101
|
+
if (!skuId) {
|
|
102
|
+
throw new Error("[ButtonBuilder] Premium buttons must have an SKU id.");
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
type: ComponentType.Button,
|
|
106
|
+
style,
|
|
107
|
+
disabled,
|
|
108
|
+
sku_id: skuId,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const customId = this.data.customId;
|
|
112
|
+
if (!customId) {
|
|
113
|
+
throw new Error("[ButtonBuilder] Non-link buttons must have a custom id.");
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
type: ComponentType.Button,
|
|
117
|
+
style,
|
|
118
|
+
label,
|
|
119
|
+
emoji: emoji ? { ...emoji } : undefined,
|
|
120
|
+
disabled,
|
|
121
|
+
custom_id: customId,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SelectMenuDefaultValueType, type APIChannelSelectComponent, type APISelectMenuDefaultValue } from "discord-api-types/v10";
|
|
2
|
+
import { ChannelType } from "../types/ChannelType.js";
|
|
3
|
+
import type { JSONEncodable } from "./shared.js";
|
|
4
|
+
/** Shape describing initial channel select menu data accepted by the builder. */
|
|
5
|
+
export type ChannelSelectMenuBuilderData = {
|
|
6
|
+
customId?: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
minValues?: number;
|
|
9
|
+
maxValues?: number;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
channelTypes?: ChannelType[];
|
|
13
|
+
defaultValues?: APISelectMenuDefaultValue<SelectMenuDefaultValueType.Channel>[];
|
|
14
|
+
};
|
|
15
|
+
/** Builder for Discord channel select menu components. */
|
|
16
|
+
export declare class ChannelSelectMenuBuilder implements JSONEncodable<APIChannelSelectComponent> {
|
|
17
|
+
private data;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new channel select menu builder with optional seed data.
|
|
20
|
+
*/
|
|
21
|
+
constructor(data?: ChannelSelectMenuBuilderData);
|
|
22
|
+
/**
|
|
23
|
+
* Sets the unique custom identifier for the select menu interaction.
|
|
24
|
+
*/
|
|
25
|
+
setCustomId(customId: string): this;
|
|
26
|
+
/**
|
|
27
|
+
* Sets or clears the placeholder text displayed when no channel is selected.
|
|
28
|
+
*/
|
|
29
|
+
setPlaceholder(placeholder: string | null | undefined): this;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the minimum number of channels that must be selected.
|
|
32
|
+
*/
|
|
33
|
+
setMinValues(minValues: number | null | undefined): this;
|
|
34
|
+
/**
|
|
35
|
+
* Sets the maximum number of channels that can be selected.
|
|
36
|
+
*/
|
|
37
|
+
setMaxValues(maxValues: number | null | undefined): this;
|
|
38
|
+
/**
|
|
39
|
+
* Toggles whether the select menu is disabled.
|
|
40
|
+
*/
|
|
41
|
+
setDisabled(disabled: boolean): this;
|
|
42
|
+
/**
|
|
43
|
+
* Marks the select menu as requiring at least the minimum number of selections.
|
|
44
|
+
*/
|
|
45
|
+
setRequired(required: boolean): this;
|
|
46
|
+
/**
|
|
47
|
+
* Filters selectable channels by the provided channel types.
|
|
48
|
+
*/
|
|
49
|
+
setChannelTypes(channelTypes: Iterable<ChannelType>): this;
|
|
50
|
+
/**
|
|
51
|
+
* Replaces the default channel selections displayed when the menu renders.
|
|
52
|
+
*/
|
|
53
|
+
setDefaultValues(defaultValues: Iterable<APISelectMenuDefaultValue<SelectMenuDefaultValueType.Channel>>): this;
|
|
54
|
+
/**
|
|
55
|
+
* Serialises the builder into an API compatible channel select menu payload.
|
|
56
|
+
*/
|
|
57
|
+
toJSON(): APIChannelSelectComponent;
|
|
58
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ComponentType, SelectMenuDefaultValueType, } from "discord-api-types/v10";
|
|
2
|
+
/** Builder for Discord channel select menu components. */
|
|
3
|
+
export class ChannelSelectMenuBuilder {
|
|
4
|
+
data;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new channel 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
|
+
required: data.required,
|
|
16
|
+
channelTypes: data.channelTypes
|
|
17
|
+
? [...data.channelTypes]
|
|
18
|
+
: undefined,
|
|
19
|
+
defaultValues: data.defaultValues
|
|
20
|
+
? data.defaultValues.map((value) => ({
|
|
21
|
+
...value,
|
|
22
|
+
type: SelectMenuDefaultValueType.Channel,
|
|
23
|
+
}))
|
|
24
|
+
: undefined,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Sets the unique custom identifier for the select menu interaction.
|
|
29
|
+
*/
|
|
30
|
+
setCustomId(customId) {
|
|
31
|
+
this.data.customId = customId;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sets or clears the placeholder text displayed when no channel is selected.
|
|
36
|
+
*/
|
|
37
|
+
setPlaceholder(placeholder) {
|
|
38
|
+
this.data.placeholder = placeholder ?? undefined;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Sets the minimum number of channels that must be selected.
|
|
43
|
+
*/
|
|
44
|
+
setMinValues(minValues) {
|
|
45
|
+
this.data.minValues = minValues ?? undefined;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sets the maximum number of channels that can be selected.
|
|
50
|
+
*/
|
|
51
|
+
setMaxValues(maxValues) {
|
|
52
|
+
this.data.maxValues = maxValues ?? undefined;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Toggles whether the select menu is disabled.
|
|
57
|
+
*/
|
|
58
|
+
setDisabled(disabled) {
|
|
59
|
+
this.data.disabled = disabled;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Marks the select menu as requiring at least the minimum number of selections.
|
|
64
|
+
*/
|
|
65
|
+
setRequired(required) {
|
|
66
|
+
this.data.required = required;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Filters selectable channels by the provided channel types.
|
|
71
|
+
*/
|
|
72
|
+
setChannelTypes(channelTypes) {
|
|
73
|
+
this.data.channelTypes = Array.from(channelTypes);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Replaces the default channel selections displayed when the menu renders.
|
|
78
|
+
*/
|
|
79
|
+
setDefaultValues(defaultValues) {
|
|
80
|
+
this.data.defaultValues = Array.from(defaultValues, (value) => ({
|
|
81
|
+
...value,
|
|
82
|
+
type: SelectMenuDefaultValueType.Channel,
|
|
83
|
+
}));
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Serialises the builder into an API compatible channel select menu payload.
|
|
88
|
+
*/
|
|
89
|
+
toJSON() {
|
|
90
|
+
const { customId } = this.data;
|
|
91
|
+
if (!customId) {
|
|
92
|
+
throw new Error("[ChannelSelectMenuBuilder] custom id is required.");
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
type: ComponentType.ChannelSelect,
|
|
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
|
+
required: this.data.required,
|
|
102
|
+
channel_types: this.data.channelTypes
|
|
103
|
+
? [...this.data.channelTypes]
|
|
104
|
+
: undefined,
|
|
105
|
+
default_values: this.data.defaultValues?.map((value) => ({
|
|
106
|
+
...value,
|
|
107
|
+
type: SelectMenuDefaultValueType.Channel,
|
|
108
|
+
})),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { APIModalInteractionResponseCallbackComponent, APIModalInteractionResponseCallbackData } from "discord-api-types/v10";
|
|
2
|
+
import type { JSONEncodable } from "./shared.js";
|
|
3
|
+
/** Values accepted when composing modal component rows. */
|
|
4
|
+
export type ModalComponentLike = JSONEncodable<APIModalInteractionResponseCallbackComponent> | APIModalInteractionResponseCallbackComponent;
|
|
5
|
+
/** Shape describing initial modal data accepted by the builder. */
|
|
6
|
+
export type ModalBuilderData = {
|
|
7
|
+
customId?: string;
|
|
8
|
+
title?: string;
|
|
9
|
+
components?: Iterable<ModalComponentLike>;
|
|
10
|
+
};
|
|
11
|
+
/** Builder for Discord modal interaction responses. */
|
|
12
|
+
export declare class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCallbackData> {
|
|
13
|
+
private customId?;
|
|
14
|
+
private title?;
|
|
15
|
+
private components;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new modal builder with optional seed data.
|
|
18
|
+
*/
|
|
19
|
+
constructor(data?: ModalBuilderData);
|
|
20
|
+
/**
|
|
21
|
+
* Sets the custom identifier returned when the modal is submitted.
|
|
22
|
+
*/
|
|
23
|
+
setCustomId(customId: string): this;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the modal title displayed to users.
|
|
26
|
+
*/
|
|
27
|
+
setTitle(title: string): this;
|
|
28
|
+
/**
|
|
29
|
+
* Appends component rows to the modal body.
|
|
30
|
+
*/
|
|
31
|
+
addComponents(...components: ModalComponentLike[]): this;
|
|
32
|
+
/**
|
|
33
|
+
* Replaces all component rows for the modal.
|
|
34
|
+
*/
|
|
35
|
+
setComponents(components: Iterable<ModalComponentLike>): this;
|
|
36
|
+
/**
|
|
37
|
+
* Serialises the builder into an API compatible modal response payload.
|
|
38
|
+
*/
|
|
39
|
+
toJSON(): APIModalInteractionResponseCallbackData;
|
|
40
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { resolveJSONEncodable } from "./shared.js";
|
|
2
|
+
/** Builder for Discord modal interaction responses. */
|
|
3
|
+
export class ModalBuilder {
|
|
4
|
+
customId;
|
|
5
|
+
title;
|
|
6
|
+
components;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new modal builder with optional seed data.
|
|
9
|
+
*/
|
|
10
|
+
constructor(data = {}) {
|
|
11
|
+
this.customId = data.customId;
|
|
12
|
+
this.title = data.title;
|
|
13
|
+
this.components = data.components ? Array.from(data.components) : [];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Sets the custom identifier returned when the modal is submitted.
|
|
17
|
+
*/
|
|
18
|
+
setCustomId(customId) {
|
|
19
|
+
this.customId = customId;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sets the modal title displayed to users.
|
|
24
|
+
*/
|
|
25
|
+
setTitle(title) {
|
|
26
|
+
this.title = title;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Appends component rows to the modal body.
|
|
31
|
+
*/
|
|
32
|
+
addComponents(...components) {
|
|
33
|
+
this.components.push(...components);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Replaces all component rows for the modal.
|
|
38
|
+
*/
|
|
39
|
+
setComponents(components) {
|
|
40
|
+
this.components = Array.from(components);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Serialises the builder into an API compatible modal response payload.
|
|
45
|
+
*/
|
|
46
|
+
toJSON() {
|
|
47
|
+
if (!this.customId) {
|
|
48
|
+
throw new Error("[ModalBuilder] custom id is required.");
|
|
49
|
+
}
|
|
50
|
+
if (!this.title) {
|
|
51
|
+
throw new Error("[ModalBuilder] title is required.");
|
|
52
|
+
}
|
|
53
|
+
if (this.components.length === 0) {
|
|
54
|
+
throw new Error("[ModalBuilder] at least one component is required.");
|
|
55
|
+
}
|
|
56
|
+
if (this.components.length > 5) {
|
|
57
|
+
throw new Error("[ModalBuilder] no more than 5 components can be provided.");
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
custom_id: this.customId,
|
|
61
|
+
title: this.title,
|
|
62
|
+
components: this.components.map((component) => resolveJSONEncodable(component)),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
required?: boolean;
|
|
11
|
+
defaultValues?: APISelectMenuDefaultValue<SelectMenuDefaultValueType.Role>[];
|
|
12
|
+
};
|
|
13
|
+
/** Builder for Discord role select menu components. */
|
|
14
|
+
export declare class RoleSelectMenuBuilder implements JSONEncodable<APIRoleSelectComponent> {
|
|
15
|
+
private data;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new role select menu builder with optional seed data.
|
|
18
|
+
*/
|
|
19
|
+
constructor(data?: RoleSelectMenuBuilderData);
|
|
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 role is selected.
|
|
26
|
+
*/
|
|
27
|
+
setPlaceholder(placeholder: string | null | undefined): this;
|
|
28
|
+
/**
|
|
29
|
+
* Sets the minimum number of roles that must be selected.
|
|
30
|
+
*/
|
|
31
|
+
setMinValues(minValues: number | null | undefined): this;
|
|
32
|
+
/**
|
|
33
|
+
* Sets the maximum number of roles 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
|
+
* Marks the select menu as requiring at least the minimum number of selections.
|
|
42
|
+
*/
|
|
43
|
+
setRequired(required: boolean): this;
|
|
44
|
+
/**
|
|
45
|
+
* Replaces the default role selections displayed when the menu renders.
|
|
46
|
+
*/
|
|
47
|
+
setDefaultValues(defaultValues: Iterable<APISelectMenuDefaultValue<SelectMenuDefaultValueType.Role>>): this;
|
|
48
|
+
/**
|
|
49
|
+
* Serialises the builder into an API compatible role select menu payload.
|
|
50
|
+
*/
|
|
51
|
+
toJSON(): APIRoleSelectComponent;
|
|
52
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
required: data.required,
|
|
16
|
+
defaultValues: data.defaultValues
|
|
17
|
+
? data.defaultValues.map((value) => ({
|
|
18
|
+
...value,
|
|
19
|
+
type: SelectMenuDefaultValueType.Role,
|
|
20
|
+
}))
|
|
21
|
+
: undefined,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Sets the unique custom identifier for the select menu interaction.
|
|
26
|
+
*/
|
|
27
|
+
setCustomId(customId) {
|
|
28
|
+
this.data.customId = customId;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Sets or clears the placeholder text displayed when no role is selected.
|
|
33
|
+
*/
|
|
34
|
+
setPlaceholder(placeholder) {
|
|
35
|
+
this.data.placeholder = placeholder ?? undefined;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Sets the minimum number of roles that must be selected.
|
|
40
|
+
*/
|
|
41
|
+
setMinValues(minValues) {
|
|
42
|
+
this.data.minValues = minValues ?? undefined;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Sets the maximum number of roles that can be selected.
|
|
47
|
+
*/
|
|
48
|
+
setMaxValues(maxValues) {
|
|
49
|
+
this.data.maxValues = maxValues ?? undefined;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Toggles whether the select menu is disabled.
|
|
54
|
+
*/
|
|
55
|
+
setDisabled(disabled) {
|
|
56
|
+
this.data.disabled = disabled;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Marks the select menu as requiring at least the minimum number of selections.
|
|
61
|
+
*/
|
|
62
|
+
setRequired(required) {
|
|
63
|
+
this.data.required = required;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Replaces the default role selections displayed when the menu renders.
|
|
68
|
+
*/
|
|
69
|
+
setDefaultValues(defaultValues) {
|
|
70
|
+
this.data.defaultValues = Array.from(defaultValues, (value) => ({
|
|
71
|
+
...value,
|
|
72
|
+
type: SelectMenuDefaultValueType.Role,
|
|
73
|
+
}));
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Serialises the builder into an API compatible role select menu payload.
|
|
78
|
+
*/
|
|
79
|
+
toJSON() {
|
|
80
|
+
const { customId } = this.data;
|
|
81
|
+
if (!customId) {
|
|
82
|
+
throw new Error("[RoleSelectMenuBuilder] custom id is required.");
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
type: ComponentType.RoleSelect,
|
|
86
|
+
custom_id: customId,
|
|
87
|
+
placeholder: this.data.placeholder,
|
|
88
|
+
min_values: this.data.minValues,
|
|
89
|
+
max_values: this.data.maxValues,
|
|
90
|
+
disabled: this.data.disabled,
|
|
91
|
+
required: this.data.required,
|
|
92
|
+
default_values: this.data.defaultValues?.map((value) => ({
|
|
93
|
+
...value,
|
|
94
|
+
type: SelectMenuDefaultValueType.Role,
|
|
95
|
+
})),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|