js-discord-modularcommand 3.2.1 → 3.2.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.
- package/dist/modularbutton.d.ts +12 -0
- package/dist/modularbutton.js +20 -3
- package/dist/modularselectmenu.d.ts +12 -0
- package/dist/modularselectmenu.js +18 -0
- package/dist/registercommand.js +13 -1
- package/package.json +1 -1
package/dist/modularbutton.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export default class ModularButton {
|
|
|
22
22
|
command: ModularCommand;
|
|
23
23
|
/** Use other mechanisms to handle button interactions. */
|
|
24
24
|
execute: ButtonExecuteFunction;
|
|
25
|
+
/** Whether the button should be interacted by all users. */
|
|
26
|
+
allowOthers: boolean;
|
|
25
27
|
/**
|
|
26
28
|
* @description Creates a new ModularButton instance.
|
|
27
29
|
* @param {string} customId The custom ID for the button. This should be unique within the context of a message.
|
|
@@ -49,4 +51,14 @@ export default class ModularButton {
|
|
|
49
51
|
* @returns {ButtonBuilder} The built ButtonBuilder instance with localized label.
|
|
50
52
|
*/
|
|
51
53
|
build(locale: LocaleKey): ButtonBuilder;
|
|
54
|
+
/**
|
|
55
|
+
* @description Sets whether the button should be interacted by all users.
|
|
56
|
+
* @returns {this} The current ModularButton instance for method chaining.
|
|
57
|
+
*/
|
|
58
|
+
setAllowOthers(): this;
|
|
59
|
+
/**
|
|
60
|
+
* @description Retrieves the allowOthers property of the button.
|
|
61
|
+
* @returns {boolean} The allowOthers property of the button.
|
|
62
|
+
*/
|
|
63
|
+
setOnlyAuthor(): this;
|
|
52
64
|
}
|
package/dist/modularbutton.js
CHANGED
|
@@ -25,16 +25,17 @@ class ModularButton {
|
|
|
25
25
|
constructor(customId, command) {
|
|
26
26
|
/** Use other mechanisms to handle button interactions. */
|
|
27
27
|
this.execute = async () => { };
|
|
28
|
+
/** Whether the button should be interacted by all users. */
|
|
29
|
+
this.allowOthers = false;
|
|
28
30
|
if (!customId || typeof customId !== "string") {
|
|
29
31
|
throw new Error("Custom ID must be a non-empty string.");
|
|
30
32
|
}
|
|
31
33
|
if (!command.name || typeof command.name !== "string") {
|
|
32
34
|
throw new Error("ModularCommand must have a valid name.");
|
|
33
35
|
}
|
|
34
|
-
this.buttonObject = new discord_js_1.ButtonBuilder()
|
|
35
|
-
.setCustomId(`${command.name}_${customId}`);
|
|
36
|
-
this.command = command;
|
|
37
36
|
this.customId = `${command.name}_${customId}`;
|
|
37
|
+
this.buttonObject = new discord_js_1.ButtonBuilder().setCustomId(this.customId);
|
|
38
|
+
this.command = command;
|
|
38
39
|
this.buttonId = customId;
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
@@ -76,5 +77,21 @@ class ModularButton {
|
|
|
76
77
|
this.buttonObject.setLabel(locale[labelKey]);
|
|
77
78
|
return this.buttonObject;
|
|
78
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* @description Sets whether the button should be interacted by all users.
|
|
82
|
+
* @returns {this} The current ModularButton instance for method chaining.
|
|
83
|
+
*/
|
|
84
|
+
setAllowOthers() {
|
|
85
|
+
this.allowOthers = true;
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @description Retrieves the allowOthers property of the button.
|
|
90
|
+
* @returns {boolean} The allowOthers property of the button.
|
|
91
|
+
*/
|
|
92
|
+
setOnlyAuthor() {
|
|
93
|
+
this.allowOthers = false;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
79
96
|
}
|
|
80
97
|
exports.default = ModularButton;
|
|
@@ -24,6 +24,8 @@ export default class ModularSelectMenu {
|
|
|
24
24
|
command: ModularCommand;
|
|
25
25
|
/** The function to execute when the select menu is interacted with. */
|
|
26
26
|
execute: SelectMenuExecuteFunction;
|
|
27
|
+
/** Whether the select menu should be interacted by all users. */
|
|
28
|
+
allowOthers: boolean;
|
|
27
29
|
/**
|
|
28
30
|
* @description Creates a new ModularSelectMenu instance.
|
|
29
31
|
* @param {string} selectMenuId The base ID for the select menu.
|
|
@@ -59,4 +61,14 @@ export default class ModularSelectMenu {
|
|
|
59
61
|
* @returns {StringSelectMenuBuilder} The fully constructed select menu object ready to be sent to a user.
|
|
60
62
|
*/
|
|
61
63
|
build(locale: LocaleKey): StringSelectMenuBuilder;
|
|
64
|
+
/**
|
|
65
|
+
* @description Sets whether the select menu should be interacted by all users.
|
|
66
|
+
* @returns {this} The current ModularSelectMenu instance for method chaining.
|
|
67
|
+
*/
|
|
68
|
+
setAllowOthers(): this;
|
|
69
|
+
/**
|
|
70
|
+
* @description Retrieves the allowOthers property of the select menu.
|
|
71
|
+
* @returns {boolean} The allowOthers property of the select menu.
|
|
72
|
+
*/
|
|
73
|
+
setOnlyAuthor(): this;
|
|
62
74
|
}
|
|
@@ -26,6 +26,8 @@ class ModularSelectMenu {
|
|
|
26
26
|
constructor(selectMenuId, command) {
|
|
27
27
|
/** The function to execute when the select menu is interacted with. */
|
|
28
28
|
this.execute = async () => { };
|
|
29
|
+
/** Whether the select menu should be interacted by all users. */
|
|
30
|
+
this.allowOthers = false;
|
|
29
31
|
if (!selectMenuId || typeof selectMenuId !== "string") {
|
|
30
32
|
throw new Error("Select Menu ID must be a non-empty string.");
|
|
31
33
|
}
|
|
@@ -107,5 +109,21 @@ class ModularSelectMenu {
|
|
|
107
109
|
}
|
|
108
110
|
return this.selectMenuObject;
|
|
109
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* @description Sets whether the select menu should be interacted by all users.
|
|
114
|
+
* @returns {this} The current ModularSelectMenu instance for method chaining.
|
|
115
|
+
*/
|
|
116
|
+
setAllowOthers() {
|
|
117
|
+
this.allowOthers = true;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @description Retrieves the allowOthers property of the select menu.
|
|
122
|
+
* @returns {boolean} The allowOthers property of the select menu.
|
|
123
|
+
*/
|
|
124
|
+
setOnlyAuthor() {
|
|
125
|
+
this.allowOthers = false;
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
110
128
|
}
|
|
111
129
|
exports.default = ModularSelectMenu;
|
package/dist/registercommand.js
CHANGED
|
@@ -254,7 +254,11 @@ function getCommandLocale(command, interaction) {
|
|
|
254
254
|
function createChatInputExecutor(command, options) {
|
|
255
255
|
return async (interaction) => {
|
|
256
256
|
// Permission & NSFW Checks
|
|
257
|
-
|
|
257
|
+
let hasPermission = true;
|
|
258
|
+
if (command.permissionCheck !== undefined) {
|
|
259
|
+
hasPermission = await command.permissionCheck(interaction);
|
|
260
|
+
}
|
|
261
|
+
if (!hasPermission) {
|
|
258
262
|
await interaction.reply({ content: locales_1.LOCALE_FORBIDDEN[interaction.locale], flags: discord_js_1.MessageFlags.Ephemeral });
|
|
259
263
|
return;
|
|
260
264
|
}
|
|
@@ -371,6 +375,10 @@ function createButtonExecutor(command) {
|
|
|
371
375
|
const buttonObject = command.buttons.get(interaction.customId.split('_')[1]);
|
|
372
376
|
if (!buttonObject)
|
|
373
377
|
return;
|
|
378
|
+
if (!buttonObject.allowOthers && interaction.user.id !== interaction.message.author.id) {
|
|
379
|
+
await interaction.reply({ content: locales_1.LOCALE_FORBIDDEN[interaction.locale], flags: discord_js_1.MessageFlags.Ephemeral });
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
374
382
|
await buttonObject.execute({
|
|
375
383
|
interaction,
|
|
376
384
|
command,
|
|
@@ -391,6 +399,10 @@ function createSelectMenuExecutor(command) {
|
|
|
391
399
|
const menuObject = command.selectMenus.get(interaction.customId.split('_')[1]);
|
|
392
400
|
if (!menuObject)
|
|
393
401
|
return;
|
|
402
|
+
if (!menuObject.allowOthers && interaction.user.id !== interaction.message.author.id) {
|
|
403
|
+
await interaction.reply({ content: locales_1.LOCALE_FORBIDDEN[interaction.locale], flags: discord_js_1.MessageFlags.Ephemeral });
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
394
406
|
// The user's selected option value is abstracted into `selected`.
|
|
395
407
|
await menuObject.execute({
|
|
396
408
|
interaction,
|