js-discord-modularcommand 2.3.0 → 2.3.2

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.
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { ButtonBuilder, ButtonStyle } from "discord.js";
7
7
  import { ButtonExecuteFunction } from "./types";
8
+ import ModularCommand from "./modularcommand";
8
9
  /**
9
10
  * @class ModularButton
10
11
  * @description A class to create and manage reusable button components.
@@ -14,21 +15,23 @@ export default class ModularButton {
14
15
  buttonObject: ButtonBuilder;
15
16
  /** The custom ID for the button, used to identify it in interactions. */
16
17
  customId: string;
18
+ /** The base ID for the button, used for localization. */
19
+ buttonId: string;
17
20
  /** The visual style of the button. */
18
21
  style: ButtonStyle;
19
- /**
20
- * @deprecated This property is deprecated and will be removed in future versions.
21
- * Use other mechanisms to handle button interactions.
22
- */
22
+ /** Use other mechanisms to handle button interactions. */
23
23
  execute: ButtonExecuteFunction;
24
24
  /**
25
25
  * @description Creates a new ModularButton instance.
26
26
  * @param {string} customId The custom ID for the button. This should be unique within the context of a message.
27
27
  */
28
- constructor(customId: string);
28
+ constructor(customId: string, command: ModularCommand);
29
+ /**
30
+ * @description Retrieves the underlying ButtonBuilder instance.
31
+ * @returns {ButtonBuilder} The ButtonBuilder instance.
32
+ */
33
+ getButton(): ButtonBuilder;
29
34
  /**
30
- * @deprecated This method is deprecated and will be removed in future versions.
31
- * Use other mechanisms to handle button interactions.
32
35
  * @description Sets the execution function for the button's click event.
33
36
  * @param {ButtonExecuteFunction} executeFunction The function to run when the button is interacted with.
34
37
  * @returns {this} The current ModularButton instance for method chaining.
@@ -18,20 +18,23 @@ class ModularButton {
18
18
  * @description Creates a new ModularButton instance.
19
19
  * @param {string} customId The custom ID for the button. This should be unique within the context of a message.
20
20
  */
21
- constructor(customId) {
22
- /**
23
- * @deprecated This property is deprecated and will be removed in future versions.
24
- * Use other mechanisms to handle button interactions.
25
- */
21
+ constructor(customId, command) {
22
+ /** Use other mechanisms to handle button interactions. */
26
23
  this.execute = async () => { };
27
24
  this.buttonObject = new discord_js_1.ButtonBuilder()
28
- .setCustomId(customId);
29
- this.customId = customId;
25
+ .setCustomId(`${command.name}_${customId}`);
26
+ this.customId = `${command.name}_${customId}`;
27
+ this.buttonId = customId;
30
28
  this.style = discord_js_1.ButtonStyle.Primary;
31
29
  }
32
30
  /**
33
- * @deprecated This method is deprecated and will be removed in future versions.
34
- * Use other mechanisms to handle button interactions.
31
+ * @description Retrieves the underlying ButtonBuilder instance.
32
+ * @returns {ButtonBuilder} The ButtonBuilder instance.
33
+ */
34
+ getButton() {
35
+ return this.buttonObject;
36
+ }
37
+ /**
35
38
  * @description Sets the execution function for the button's click event.
36
39
  * @param {ButtonExecuteFunction} executeFunction The function to run when the button is interacted with.
37
40
  * @returns {this} The current ModularButton instance for method chaining.
@@ -190,10 +190,10 @@ class ModularCommand {
190
190
  * @return {ModularButton} The created button instance.
191
191
  */
192
192
  addButton(customId, execute) {
193
- const button = new modularbutton_js_1.default(customId);
193
+ const button = new modularbutton_js_1.default(customId, this);
194
+ button.setExecute(execute);
194
195
  this.buttons.set(customId, button);
195
196
  this.buttonsArray.push(button);
196
- this.addCustomIDHandler(customId, execute);
197
197
  return button;
198
198
  }
199
199
  }
@@ -29,6 +29,11 @@ export default class ModularModal {
29
29
  * @param {ModularCommand} command The command that this modal is associated with.
30
30
  */
31
31
  constructor(modalId: string, command: ModularCommand);
32
+ /**
33
+ * @description Retrieves the underlying ModalBuilder instance.
34
+ * @returns {ModalBuilder} The ModalBuilder instance.
35
+ */
36
+ getModal(): ModalBuilder;
32
37
  /**
33
38
  * @description Sets the execution function for the modal's submission event.
34
39
  * @param {ModalExecuteFunction} executeFunction The function to run when the modal is submitted.
@@ -28,6 +28,13 @@ class ModularModal {
28
28
  this.modalObject = new discord_js_1.ModalBuilder().setCustomId(this.customId);
29
29
  this.modalInputs = new Map();
30
30
  }
31
+ /**
32
+ * @description Retrieves the underlying ModalBuilder instance.
33
+ * @returns {ModalBuilder} The ModalBuilder instance.
34
+ */
35
+ getModal() {
36
+ return this.modalObject;
37
+ }
31
38
  /**
32
39
  * @description Sets the execution function for the modal's submission event.
33
40
  * @param {ModalExecuteFunction} executeFunction The function to run when the modal is submitted.
@@ -146,7 +146,7 @@ function createModalExecutor(command) {
146
146
  if (command.modals.size === 0)
147
147
  return undefined;
148
148
  return async (interaction) => {
149
- const modalObject = command.modals.get(interaction.customId);
149
+ const modalObject = command.modals.get(interaction.customId.split('_')[1]);
150
150
  if (!modalObject)
151
151
  return;
152
152
  const args = {};
@@ -170,7 +170,7 @@ function createButtonExecutor(command) {
170
170
  if (command.buttons.size === 0)
171
171
  return undefined;
172
172
  return async (interaction) => {
173
- const buttonObject = command.buttons.get(interaction.customId);
173
+ const buttonObject = command.buttons.get(interaction.customId.split('_')[1]);
174
174
  if (!buttonObject)
175
175
  return;
176
176
  await buttonObject.execute({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-discord-modularcommand",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "discord",