js-discord-modularcommand 2.3.2 → 2.4.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.
@@ -3,8 +3,8 @@
3
3
  * @author vicentefelipechile
4
4
  * @license MIT
5
5
  */
6
- import { ButtonBuilder, ButtonStyle } from "discord.js";
7
- import { ButtonExecuteFunction } from "./types";
6
+ import { ButtonBuilder } from "discord.js";
7
+ import { ButtonExecuteFunction, LocaleKey } from "./types";
8
8
  import ModularCommand from "./modularcommand";
9
9
  /**
10
10
  * @class ModularButton
@@ -17,8 +17,8 @@ export default class ModularButton {
17
17
  customId: string;
18
18
  /** The base ID for the button, used for localization. */
19
19
  buttonId: string;
20
- /** The visual style of the button. */
21
- style: ButtonStyle;
20
+ /** The command instance to which this modal belongs. */
21
+ command: ModularCommand;
22
22
  /** Use other mechanisms to handle button interactions. */
23
23
  execute: ButtonExecuteFunction;
24
24
  /**
@@ -31,10 +31,21 @@ export default class ModularButton {
31
31
  * @returns {ButtonBuilder} The ButtonBuilder instance.
32
32
  */
33
33
  getButton(): ButtonBuilder;
34
+ /**
35
+ * @description Retrieves the custom ID of the button.
36
+ * @returns {string} The custom ID of the button.
37
+ */
38
+ getCustomId(): string;
34
39
  /**
35
40
  * @description Sets the execution function for the button's click event.
36
41
  * @param {ButtonExecuteFunction} executeFunction The function to run when the button is interacted with.
37
42
  * @returns {this} The current ModularButton instance for method chaining.
38
43
  */
39
44
  setExecute(executeFunction: ButtonExecuteFunction): this;
45
+ /**
46
+ * @description Builds the button with localized label.
47
+ * @param {LocaleKey} locale The locale object containing localized strings.
48
+ * @returns {ButtonBuilder} The built ButtonBuilder instance with localized label.
49
+ */
50
+ build(locale: LocaleKey): ButtonBuilder;
40
51
  }
@@ -23,9 +23,9 @@ class ModularButton {
23
23
  this.execute = async () => { };
24
24
  this.buttonObject = new discord_js_1.ButtonBuilder()
25
25
  .setCustomId(`${command.name}_${customId}`);
26
+ this.command = command;
26
27
  this.customId = `${command.name}_${customId}`;
27
28
  this.buttonId = customId;
28
- this.style = discord_js_1.ButtonStyle.Primary;
29
29
  }
30
30
  /**
31
31
  * @description Retrieves the underlying ButtonBuilder instance.
@@ -34,6 +34,13 @@ class ModularButton {
34
34
  getButton() {
35
35
  return this.buttonObject;
36
36
  }
37
+ /**
38
+ * @description Retrieves the custom ID of the button.
39
+ * @returns {string} The custom ID of the button.
40
+ */
41
+ getCustomId() {
42
+ return this.customId;
43
+ }
37
44
  /**
38
45
  * @description Sets the execution function for the button's click event.
39
46
  * @param {ButtonExecuteFunction} executeFunction The function to run when the button is interacted with.
@@ -43,5 +50,14 @@ class ModularButton {
43
50
  this.execute = executeFunction;
44
51
  return this;
45
52
  }
53
+ /**
54
+ * @description Builds the button with localized label.
55
+ * @param {LocaleKey} locale The locale object containing localized strings.
56
+ * @returns {ButtonBuilder} The built ButtonBuilder instance with localized label.
57
+ */
58
+ build(locale) {
59
+ this.buttonObject.setLabel(locale[`${this.command.name}.${this.buttonId}`]);
60
+ return this.buttonObject;
61
+ }
46
62
  }
47
63
  exports.default = ModularButton;
@@ -34,6 +34,11 @@ export default class ModularModal {
34
34
  * @returns {ModalBuilder} The ModalBuilder instance.
35
35
  */
36
36
  getModal(): ModalBuilder;
37
+ /**
38
+ * @description Retrieves the custom ID of the modal.
39
+ * @returns {string} The custom ID of the modal.
40
+ */
41
+ getCustomId(): string;
37
42
  /**
38
43
  * @description Sets the execution function for the modal's submission event.
39
44
  * @param {ModalExecuteFunction} executeFunction The function to run when the modal is submitted.
@@ -35,6 +35,13 @@ class ModularModal {
35
35
  getModal() {
36
36
  return this.modalObject;
37
37
  }
38
+ /**
39
+ * @description Retrieves the custom ID of the modal.
40
+ * @returns {string} The custom ID of the modal.
41
+ */
42
+ getCustomId() {
43
+ return this.customId;
44
+ }
38
45
  /**
39
46
  * @description Sets the execution function for the modal's submission event.
40
47
  * @param {ModalExecuteFunction} executeFunction The function to run when the modal is submitted.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-discord-modularcommand",
3
- "version": "2.3.2",
3
+ "version": "2.4.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "discord",