Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit 80e5d63

Browse files
committed
Discord-Modals v1.3.2: Add ModalActionRow to Modal and ModalSubmitInteraction classes.
1 parent d47f4ca commit 80e5d63

18 files changed

+287
-210
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
Hello! This is the Change log section of Discord-Modals. Here you can see what things have been changed in the different versions, to be informed. This will be updated every time there are new versions. I hope you enjoy this package :)
44

5-
# v1.3.1 (Stable)
5+
# v1.3.2 (Stable)
6+
7+
- Compatibility: change `discord-api-types` enums from `v10` to `v9`.
8+
- `Modal` and `ModalSubmitInteraction` class: Now the `.components` property returns `ModalActionRow`s.
9+
- Code cleanup.
10+
11+
# v1.3.1
612
- Fix: change `discord-api-types` enums from `v9` to `v10`.
713

814
# v1.3.0
915

1016
- Fix bug: 'INVALID_CLIENT' error when the Client is valid on `.showModal()` method.
11-
- **Featured:** Add `ModalActionRow` class.
1217
- Now the `TextInputComponent` returns an **Action Row Component**. Add `ModalActionRow` class and types.
1318
- **Featured:** Now the `.showModal()` method supports **JSON Modals**.
1419
- Fix error typings `ModalSubmitField`.

DOCS.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,19 @@ Represents a Modal Submit Interaction.
372372
| Properties |Methods|
373373
| ------------ | ------------ |
374374
| `.customId` | `.getTextInputValue()` |
375-
| `.fields` | `.getField()` |
376-
| `.id` | `.deferReply()` |
377-
| `.applicationId` | `.reply()` |
378-
| `.channelId` | `.fetchReply()` |
379-
| `.guildId` | `.editReply()` |
380-
| `.user` | `.deleteReply()` |
381-
| `.member` | `.followUp()` |
382-
| `.memberPermissions` | `.update()` |
383-
| `.locale` | `.isFromMessage()` |
384-
| `.guildLocale` | `.isRepliable()` |
385-
| `.message` | |
386-
| `.version` | |
375+
| `.components` | `.getField()` |
376+
| `.fields` | `.deferReply()` |
377+
| `.id` | `.reply()` |
378+
| `.applicationId` | `.fetchReply()` |
379+
| `.channelId` | `.editReply()` |
380+
| `.guildId` | `.deleteReply()` |
381+
| `.user` | `.followUp()` |
382+
| `.member` | `.update()` |
383+
| `.memberPermissions` | `.isFromMessage()` |
384+
| `.locale` | `.isRepliable()` |
385+
| `.guildLocale` | |
386+
| `.message` | |
387+
| `.version` | |
387388
| `.webhook` | |
388389
| `.type` | |
389390

@@ -393,6 +394,10 @@ Represents a Modal Submit Interaction.
393394
The Custom Id of the Modal.
394395
> Returns: [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
395396
397+
#### .components
398+
The Action Rows of the modal with the Text Input Components.
399+
> Returns: [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
400+
396401
#### .fields
397402
The (Fields) Text Input Components of the Modal.
398403
> Returns: [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)

index.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
APIModalInteractionResponseCallbackData,
55
APIModalSubmitInteraction,
66
APIModalActionRowComponent,
7-
} from "discord-api-types/v10";
7+
} from "discord-api-types/v9";
88
import {
99
Client,
1010
User,
@@ -95,7 +95,7 @@ export class TextInputComponent extends BaseMessageComponent {
9595
setPlaceholder(placeholder: string): TextInputComponent;
9696
setRequired(required: boolean): TextInputComponent;
9797
setDefaultValue(value: string): TextInputComponent;
98-
toJSON(): APIModalActionRowComponent<APITextInputComponent>;
98+
toJSON(): APIModalActionRowComponent;
9999
}
100100

101101
export type TextInputStyle = "SHORT" | "LONG";
@@ -105,33 +105,33 @@ export class Modal {
105105

106106
title: string;
107107
customId: string;
108-
components: TextInputComponent[];
108+
components: ModalActionRow[];
109109

110110
setTitle(title: string): Modal;
111111
setCustomId(id: string): Modal;
112-
addComponents(...components: TextInputComponent): Modal;
113-
setComponents(...components: TextInputComponent): Modal;
112+
addComponents(...components: TextInputComponent[]): Modal;
113+
setComponents(...components: TextInputComponent[]): Modal;
114114
spliceComponents(): Modal;
115115
toJSON(): APIModalInteractionResponseCallbackData;
116116
}
117117

118-
export class ModalSubmitField extends BaseMessageComponent {
118+
export class ModalSubmitField {
119119
constructor(data?: ModalSubmitFieldData);
120120

121-
type: MessageComponentType;
121+
type: string;
122122
customId: string;
123123
value: string;
124124
}
125125

126126
export class ModalActionRow {
127127
constructor();
128128

129-
type: number;
129+
type: 'ACTION_ROW';
130130
components: APITextInputComponent[];
131131

132132
addComponent(component: TextInputComponent): ModalActionRow;
133133
componentToJSON(component: TextInputComponent): APITextInputComponent;
134-
toJSON(): APIModalActionRowComponent<APITextInputComponent>;
134+
toJSON(): APIModalActionRowComponent;
135135
}
136136

137137
export class ModalSubmitInteraction extends Interaction {

index.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const { version } = require('discord.js');
2-
let ModalSubmitInteraction = require('./src/structures/ModalSubmitInteraction');
3-
const { Error } = require('./src/structures/errors');
4-
const { InteractionTypes } = require('./src/util/Constants');
1+
const { version } = require("discord.js");
2+
let ModalSubmitInteraction = require("./src/structures/ModalSubmitInteraction");
3+
const { Error } = require("./src/structures/errors");
4+
const { InteractionTypes } = require("./src/util/Constants");
55
const discordjsVersion = new String('v' + version); // Expected: v13 or v14...
6-
if(discordjsVersion.includes('v14')) ModalSubmitInteraction = require('./src/v14/ModalSubmitInteraction');
6+
if(discordjsVersion.includes('v14')) ModalSubmitInteraction = require("./src/v14/ModalSubmitInteraction");
77

88
module.exports = (client) => {
99

@@ -35,28 +35,28 @@ module.exports = (client) => {
3535

3636
// Exports the classes according to the discord.js version.
3737

38-
if (discordjsVersion.includes('v13')) {
39-
module.exports.Modal = require('./src/structures/Modal');
40-
module.exports.TextInputComponent = require('./src/structures/TextInputComponent');
41-
module.exports.ModalSubmitInteraction = require('./src/structures/ModalSubmitInteraction');
42-
module.exports.ModalSubmitField = require('./src/structures/ModalSubmitField');
43-
module.exports.ModalActionRow = require('./src/structures/ModalActionRow');
44-
module.exports.showModal = require('./src/structures/ShowModal');
45-
module.exports.Interaction = require('./src/structures/Interaction');
46-
module.exports.InteractionResponses = require('./src/structures/interfaces/InteractionResponses');
47-
module.exports.Constants = require('./src/util/Constants');
48-
module.exports.SnowflakeUtil = require('./src/util/SnowflakeUtil');
49-
} else if (discordjsVersion.includes('v14')) {
50-
module.exports.Modal = require('./src/structures/Modal');
51-
module.exports.TextInputComponent = require('./src/structures/TextInputComponent');
52-
module.exports.ModalSubmitInteraction = require('./src/v14/ModalSubmitInteraction');
53-
module.exports.ModalSubmitField = require('./src/structures/ModalSubmitField');
54-
module.exports.ModalActionRow = require('./src/structures/ModalActionRow');
55-
module.exports.showModal = require('./src/v14/ShowModal');
56-
module.exports.Interaction = require('./src/v14/Interaction');
57-
module.exports.InteractionResponses = require('./src/v14/interfaces/InteractionResponses');
58-
module.exports.Constants = require('./src/util/Constants');
59-
module.exports.SnowflakeUtil = require('./src/util/SnowflakeUtil');
38+
if (discordjsVersion.includes("v13")) {
39+
module.exports.Modal = require("./src/structures/Modal");
40+
module.exports.TextInputComponent = require("./src/structures/TextInputComponent");
41+
module.exports.ModalSubmitInteraction = require("./src/structures/ModalSubmitInteraction");
42+
module.exports.ModalSubmitField = require("./src/structures/ModalSubmitField");
43+
module.exports.ModalActionRow = require("./src/structures/ModalActionRow");
44+
module.exports.showModal = require("./src/structures/ShowModal");
45+
module.exports.Interaction = require("./src/structures/Interaction");
46+
module.exports.InteractionResponses = require("./src/structures/interfaces/InteractionResponses");
47+
module.exports.Constants = require("./src/util/Constants");
48+
module.exports.SnowflakeUtil = require("./src/util/SnowflakeUtil");
49+
} else if (discordjsVersion.includes("v14")) {
50+
module.exports.Modal = require("./src/structures/Modal");
51+
module.exports.TextInputComponent = require("./src/structures/TextInputComponent");
52+
module.exports.ModalSubmitInteraction = require("./src/v14/ModalSubmitInteraction");
53+
module.exports.ModalSubmitField = require("./src/structures/ModalSubmitField");
54+
module.exports.ModalActionRow = require("./src/structures/ModalActionRow");
55+
module.exports.showModal = require("./src/v14/ShowModal");
56+
module.exports.Interaction = require("./src/v14/Interaction");
57+
module.exports.InteractionResponses = require("./src/v14/interfaces/InteractionResponses");
58+
module.exports.Constants = require("./src/util/Constants");
59+
module.exports.SnowflakeUtil = require("./src/util/SnowflakeUtil");
6060
}
6161

6262
/* Powered by:
@@ -67,5 +67,4 @@ if (discordjsVersion.includes('v13')) {
6767
------ Developed by 『𝑴𝒂𝒕𝒆𝒐ᵗᵉᵐ』#9999 ------
6868
6969
https://www.npmjs.com/package/discord-modals
70-
7170
*/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "discord-modals",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "Discord-Modals is a package that allows your discord.js v13 and v14 bot to create, and interact with Modals, a new Discord feature.",
55
"main": "index.js",
66
"files": [

src/structures/BaseMessageComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { TypeError } = require('./errors');
33

44
/**
55
* Represents an interactive component of a Message.
6-
*/
6+
*/
77

88
class BaseMessageComponent {
99
constructor(data) {

src/structures/Interaction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
const { Base, Permissions } = require('discord.js');
44
const SnowflakeUtil = require('../util/SnowflakeUtil');
5-
const { InteractionType } = require('discord-api-types/v10');
5+
const { InteractionType } = require('discord-api-types/v9');
66

77
/**
88
* Represents an Interaction.
99
* @extends Base
10-
*/
10+
*/
1111

1212
class Interaction extends Base {
1313
constructor(client, data) {

src/structures/Modal.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
const BaseMessageComponent = require("./BaseMessageComponent");
22
const TextInputComponent = require("./TextInputComponent");
3+
const ModalActionRow = require("./ModalActionRow")
34
const { Util } = require("discord.js");
45
const { RangeError } = require("./errors");
56

67
/**
78
* Represents a Modal Form to be shown in response to an Interaction.
8-
*/
9+
*/
910

1011
class Modal {
1112

@@ -16,49 +17,49 @@ class Modal {
1617
* .setCustomId('modal-customid')
1718
* .setTitle('Test of Discord-Modals!')
1819
* .addComponents(new TextInputComponent()); // Add a Text Input Component.
19-
*/
20+
*/
2021

2122
constructor(data = {}, client = null) {
2223

2324
/**
2425
* The Title of the Modal.
2526
* @type {String}
26-
*/
27+
*/
2728

2829
this.title = data.title ?? null;
2930

3031
/**
3132
* The Custom Id of the Modal.
3233
* @type {String}
33-
*/
34+
*/
3435

3536
this.customId = data.custom_id ?? data.customId ?? null;
3637

3738
/**
3839
* The Text Input Components of the Modal.
3940
* @type {BaseMessageComponent}
40-
*/
41+
*/
4142

42-
this.components = data.components?.map(c => BaseMessageComponent.create(c, client)) ?? [];
43+
this.components = data.components?.map(c => new ModalActionRow(c).addComponent(c.components[0])) ?? [];
4344

4445
}
4546

4647
/**
4748
* Adds the Components of the Modal.
4849
* @param {TextInputComponent} components The Text Input Components to add.
4950
* @returns {Modal} Modal.
50-
*/
51+
*/
5152

5253
addComponents(...components) {
53-
this.components.push(...components.flat(Infinity).map(c => BaseMessageComponent.create(c)));
54+
this.components.push(...components.flat(Infinity).map(c => new ModalActionRow().addComponent(c)));
5455
return this;
5556
}
5657

5758
/**
5859
* Sets the Components of the Modal.
5960
* @param {TextInputComponent} components The Text Input Components to set.
6061
* @returns {Modal} Modal.
61-
*/
62+
*/
6263

6364
setComponents(...components) {
6465
this.spliceComponents(0, this.components.length, components);
@@ -69,7 +70,7 @@ class Modal {
6970
* Sets the Custom Id of the Modal.
7071
* @param {String} customId The Custom Id of the modal.
7172
* @returns {Modal} Modal.
72-
*/
73+
*/
7374

7475
setCustomId(customId) {
7576
this.customId = Util.verifyString(customId, RangeError, 'MODAL_CUSTOM_ID');
@@ -82,7 +83,7 @@ class Modal {
8283
* @param {Number} deleteCount The number of components to remove.
8384
* @param components The replacing components.
8485
* @returns {Modal} Modal.
85-
*/
86+
*/
8687

8788
spliceComponents(index, deleteCount, ...components) {
8889
this.components.splice(index, deleteCount, ...components.flat(Infinity).map(c => BaseMessageComponent.create(c)));
@@ -93,7 +94,7 @@ class Modal {
9394
* Sets the Title of the Modal.
9495
* @param {String} title The Title of the modal.
9596
* @returns {Modal} Modal.
96-
*/
97+
*/
9798

9899
setTitle(title) {
99100
this.title = Util.verifyString(title, RangeError, 'MODAL_TITLE');

src/structures/ModalActionRow.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
const TextInputComponent = require("./TextInputComponent");
2+
const BaseMessageComponent = require("./BaseMessageComponent")
23
const { MessageComponentTypes, TextInputStyles } = require("../util/Constants");
34

45
/**
56
* Represents a Modal Action Row, that contains a Text Input Component.
67
*/
78

89
class ModalActionRow {
9-
constructor() {
10+
constructor(data = {}) {
1011

1112
/**
1213
* The type of the Modal Action Row.
1314
*/
1415

15-
this.type = MessageComponentTypes.ACTION_ROW;
16+
this.type = 'ACTION_ROW';
1617

1718
/**
1819
* The Text Input Component of this action row
19-
*/
20+
*/
21+
22+
this.components = data.components?.map(component => BaseMessageComponent.create(component)) ?? [];
2023

21-
this.components = [];
2224
}
2325

2426
/**

0 commit comments

Comments
 (0)