djs-builder 0.6.10 โ†’ 0.6.12

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/README.md CHANGED
@@ -127,8 +127,8 @@ const actionRow = new CreateRow([
127
127
  { name: 'Option 3', id: 'option3', about: 'Description for Option 3', icon: '๐Ÿ”—' },
128
128
  ], //// is should not look like this ,you selecit it in next step
129
129
  value: "id", // here you can set the value of the selected option ( defult the value is will be index (0,1,2 .....) )
130
- description: "about" // here you can set the description of the selected option ( defult the description not work )
131
- label: "name" // here you can set the label of the selected option ( defult the label is (Option 1 , Option 2 , Option 3) )
130
+ description: "about", // here you can set the description of the selected option ( defult the description not work )
131
+ label: "name", // here you can set the label of the selected option ( defult the label is (Option 1 , Option 2 , Option 3) )
132
132
  emoji: "icon" // here you can set the emoji of the selected option ( defult the emoji not work )
133
133
 
134
134
  }
@@ -230,24 +230,68 @@ module.exports = {
230
230
 
231
231
  </details>
232
232
 
233
- ## ๐Ÿ”ง Commands
234
233
 
235
- - **Slash ๐Ÿ”ง** and **Prefix ๐Ÿ“จ** Have Same Options
236
234
  <details>
237
- <summary>Options</summary>
235
+ <summary>GetUser ๐Ÿ‘ค</summary>
236
+
237
+ **๐Ÿ‘ค Utility function to get a member from a message โœจ.**
238
+
239
+ ```js
240
+ const data = await GetUser(message);
241
+ ```
242
+
243
+ ---
244
+
245
+ ### ๐Ÿ“ฆ What does it return?
246
+
247
+ ```js
248
+ {
249
+ user: <GuildMember>, // ๐ŸŽฏ The targeted member
250
+ args: [ "word1", "word2" ] // โœ๏ธ Remaining args after mention/ID
251
+ }
252
+ ```
253
+
254
+ ---
255
+
256
+ ### ๐Ÿ“Œ How does it detect the user?
257
+
258
+ 1. **Mention** inside the message
259
+
260
+ > Example: `!ban @Ahmed Breaking rules`.
261
+
262
+ 2. **User ID** directly
263
+
264
+ > Example: `!ban 123456789012345678 Spamming`.
265
+
266
+ 3. **Reply** to someoneโ€™s message
267
+
268
+ > Reply to a userโ€™s message with: `!ban`.
269
+
270
+ ---
271
+
272
+ ### ๐Ÿ› ๏ธ Example usage (ban command) ๐Ÿšซ
238
273
 
239
274
  ```js
240
- cooldown : 5, /// cooldown in seconds
241
- fastUse : true, /// fast use command without prefix
242
- permissions : ["ADMINISTRATOR"], /// permission for slash command
243
- ownerOnly : true ,/// only owner can use slash command
244
- devOnly : true /// only dev can use slash command
245
- guildOnly : true /// only guild can use slash command
246
- dmOnly : true /// only dm can use slash command
275
+ client.on("messageCreate", async (message) => {
276
+ if (!message.content.startsWith("!ban")) return;
277
+
278
+ const data = await GetUser(message);
279
+ if (!data) return message.reply("โŒ Couldn't find this user.");
280
+
281
+ const member = data.user;
282
+ const reason = data.args.join(" ") || "No reason provided";
283
+
284
+ await member.ban({ reason });
285
+ message.reply(`๐Ÿšซ ${member.user.tag} has been banned for: ${reason}`);
286
+ });
247
287
  ```
248
288
 
289
+ ---
290
+
249
291
  </details>
250
292
 
293
+
294
+
251
295
  ## Contributions
252
296
 
253
297
  Contributions are welcome! If you have any suggestions, bug reports, or feature requests, feel free to contact us on discord.
@@ -61,12 +61,16 @@ async function Wait({
61
61
  if (!channel) throw new Error("context must contain a valid channel.");
62
62
 
63
63
  if (type === "message") {
64
- const collected = await channel.awaitMessages({
65
- filter: (m) => !userId || m.author.id === userId,
66
- time,
67
- max: 1,
68
- });
69
- return collected.first() || null;
64
+ try {
65
+ const collected = await channel.awaitMessages({
66
+ filter: (m) => !userId || m.author.id === userId,
67
+ time,
68
+ max: 1,
69
+ });
70
+ return collected.first() || null;
71
+ } catch {
72
+ return null;
73
+ }
70
74
  }
71
75
 
72
76
  if (type === "button") {
@@ -76,13 +80,15 @@ async function Wait({
76
80
  "You must provide messageWithButtons when using type 'button'."
77
81
  );
78
82
 
79
- const collected = await message.awaitMessageComponent({
80
- filter: (i) => !userId || i.user.id === userId,
81
- time,
82
- });
83
- if (!collected) return null;
84
-
85
- return collected;
83
+ try {
84
+ const collected = await message.awaitMessageComponent({
85
+ filter: (i) => !userId || i.user.id === userId,
86
+ time,
87
+ });
88
+ return collected ?? null;
89
+ } catch {
90
+ return null;
91
+ }
86
92
  }
87
93
 
88
94
  if (type === "both") {
@@ -106,13 +112,13 @@ async function Wait({
106
112
  });
107
113
  collectors.push(msgCollector);
108
114
 
109
- const btnCollector = messageWithButtons.createMessageComponentCollector({
115
+ const btnCollector = message_Wait.createMessageComponentCollector({
110
116
  filter: (i) => !userId || i.user.id === userId,
111
117
  max: 1,
112
118
  time,
113
119
  });
114
120
 
115
- btnCollector.on("collect", async (i) => {
121
+ btnCollector.on("collect", (i) => {
116
122
  stop();
117
123
  resolve({ type: "button", data: i });
118
124
  });
@@ -163,7 +169,7 @@ function CreateRow(components) {
163
169
  but.setDisabled(buttonConfig.disabled);
164
170
  }
165
171
 
166
- if(buttonConfig.style === 5 && buttonConfig.url) {
172
+ if (buttonConfig.style === 5 && buttonConfig.url) {
167
173
  but.setURL(buttonConfig.url);
168
174
  }
169
175
 
@@ -204,17 +210,15 @@ function CreateRow(components) {
204
210
  selectMenu = new ChannelSelectMenuBuilder();
205
211
  }
206
212
 
207
-
208
213
  selectMenu.setCustomId(id || "selectMenu");
209
214
  selectMenu.setPlaceholder(placeholder);
210
- if (min) {
211
- const minValue = Math.min(min, data.length);
212
- selectMenu.setMinValues(minValue);
213
- selectMenu.setMaxValues(data.length);
214
- }
215
+ if (min) {
216
+ const minValue = Math.min(min, data.length);
217
+ selectMenu.setMinValues(minValue);
218
+ selectMenu.setMaxValues(data.length);
219
+ }
215
220
 
216
- if(max) selectMenu.setMaxValues(max);
217
-
221
+ if (max) selectMenu.setMaxValues(max);
218
222
 
219
223
  if (type === "string") {
220
224
  selectMenu.addOptions(selectOptions);
@@ -229,8 +233,38 @@ if(max) selectMenu.setMaxValues(max);
229
233
  return actionRows;
230
234
  }
231
235
 
236
+ //////////////////////////////////* Get User ๐Ÿ‘€
237
+
238
+ async function GetUser(message) {
239
+ const args = message.content.split(/\s+/).slice(1);
240
+ let user = message.mentions.members.first();
241
+ let new_args = args;
242
+
243
+ // ุฅุฐุง ู…ุงูƒูˆ ู…ู†ุดู† โ†’ ุฌุฑุจ ุงู„ู€ ID
244
+ if (!user && args[0]) {
245
+ const userId = args[0];
246
+ user = await message.guild.members.fetch(userId).catch(() => null);
247
+ new_args = args.slice(1);
248
+ }
232
249
 
250
+ // ุฅุฐุง ู…ุงูƒูˆ ู…ู†ุดู† ูˆู„ุง ID โ†’ ุฌุฑุจ ุงู„ุฑุฏ
251
+ if (!user && message.reference) {
252
+ const repliedMessage = await message.channel.messages
253
+ .fetch(message.reference.messageId)
254
+ .catch(() => null);
233
255
 
256
+ if (repliedMessage) {
257
+ user = await message.guild.members.fetch(repliedMessage.author.id).catch(() => null);
258
+ }
259
+ }
260
+
261
+ if (!user) return null;
262
+
263
+ return {
264
+ user,
265
+ args: new_args,
266
+ };
267
+ }
234
268
 
235
269
 
236
- module.exports = { Wait, CreateBar, CreateRow };
270
+ module.exports = { Wait, CreateBar, CreateRow , GetUser};
package/handler/helper.js CHANGED
@@ -198,6 +198,14 @@ async function cmd_log(client, data, commandName, channelId) {
198
198
  const logChannel = client.channels.cache.get(channelId);
199
199
  if (!logChannel) return;
200
200
 
201
+ let messageLink;
202
+ if (interaction.channel) {
203
+ messageLink = `https://discord.com/channels/${interaction.guild.id}/${interaction.channel.id}/${interaction.id}`;
204
+ } else {
205
+ messageLink = "Unknown";
206
+ }
207
+
208
+
201
209
  const field = [
202
210
  {
203
211
  name: "๐Ÿ“ง Cmd:",
@@ -206,7 +214,9 @@ async function cmd_log(client, data, commandName, channelId) {
206
214
  },
207
215
  {
208
216
  name: "๐Ÿ‘ค User:",
209
- value: `- ${user?.tag ?? "Unknown user"} | (\`${user?.id ?? "Unknown ID"}\`)`,
217
+ value: `- ${user?.tag ?? "Unknown user"} | (\`${
218
+ user?.id ?? "Unknown ID"
219
+ }\`)`,
210
220
  inline: true,
211
221
  },
212
222
  {
@@ -235,10 +245,7 @@ async function cmd_log(client, data, commandName, channelId) {
235
245
  },
236
246
  {
237
247
  name: "๐Ÿ”— Message",
238
- value:
239
- data.message && data.message.url
240
- ? `- [Link](${data.message.url})`
241
- : "not found",
248
+ value: messageLink ? `- [Link](${messageLink})` : "not found",
242
249
  inline: true,
243
250
  }
244
251
  );
@@ -273,7 +280,6 @@ async function cmd_log(client, data, commandName, channelId) {
273
280
  }
274
281
  }
275
282
 
276
-
277
283
  //////////////////////////////////* Check update ๐Ÿ”ผ
278
284
 
279
285
  async function update(client, id, webhookURL) {
@@ -283,7 +289,8 @@ async function update(client, id, webhookURL) {
283
289
  `https://registry.npmjs.org/djs-builder/latest`
284
290
  );
285
291
  const new_version = data.version;
286
- const note = data.discription || "";
292
+ const note = data.description || "";
293
+
287
294
 
288
295
  if (
289
296
  client.djs_builder_version &&
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  {
3
3
  "name": "djs-builder",
4
- "version": "0.6.10",
5
- "description": "Discord.js bot builder. Supports Ts and Js.",
4
+ "version": "0.6.12",
5
+ "description": "\n> New features added:\n- `GetUser`: Easily fetch a user from **ID**, **mention**, or even from a **reply**.\n\n๐Ÿ›  Fixes:\n- Minor bugs fixed\n- Improved stability and error handling\n",
6
6
  "main": "handler/starter.js",
7
7
  "dependencies": {
8
8
  "axios": "^1.11.0",