@spatulox/simplediscordbot 2.0.1 → 2.0.3

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/index.d.mts CHANGED
@@ -264,9 +264,10 @@ declare class WebhookManager {
264
264
  /**
265
265
  * Récupère le channel à partir de l'ID ou utilise directement si TextChannel/ThreadChannel
266
266
  */
267
- private getTextChannel;
267
+ private getChannel;
268
268
  /**
269
269
  * Get or create webhook (lazy initialization)
270
+ * Create the webhook in the parent channel if it's in a thread
270
271
  */
271
272
  private getWebhook;
272
273
  /**
package/dist/index.d.ts CHANGED
@@ -264,9 +264,10 @@ declare class WebhookManager {
264
264
  /**
265
265
  * Récupère le channel à partir de l'ID ou utilise directement si TextChannel/ThreadChannel
266
266
  */
267
- private getTextChannel;
267
+ private getChannel;
268
268
  /**
269
269
  * Get or create webhook (lazy initialization)
270
+ * Create the webhook in the parent channel if it's in a thread
270
271
  */
271
272
  private getWebhook;
272
273
  /**
package/dist/index.js CHANGED
@@ -14559,22 +14559,38 @@ var WebhookManager = class {
14559
14559
  /**
14560
14560
  * Récupère le channel à partir de l'ID ou utilise directement si TextChannel/ThreadChannel
14561
14561
  */
14562
- async getTextChannel(channelId) {
14562
+ async getChannel(channelId) {
14563
14563
  const channel = await this.client.channels.fetch(channelId);
14564
- if (!channel || !(channel instanceof import_discord7.TextChannel)) {
14565
- throw new Error(`Channel ${channelId} is not a TextChannel`);
14564
+ if (!channel) {
14565
+ throw new Error(`Channel ${channelId} not found`);
14566
+ }
14567
+ if (!(channel instanceof import_discord7.TextChannel) && !(channel instanceof import_discord7.ThreadChannel)) {
14568
+ throw new Error(`Channel ${channelId} is not a TextChannel nor a ThreadChannel`);
14566
14569
  }
14567
14570
  return channel;
14568
14571
  }
14569
14572
  /**
14570
14573
  * Get or create webhook (lazy initialization)
14574
+ * Create the webhook in the parent channel if it's in a thread
14571
14575
  */
14572
14576
  async getWebhook(channelId) {
14573
14577
  if (this.webhook) return this.webhook;
14574
14578
  try {
14575
- const textChannel = await this.getTextChannel(channelId);
14579
+ const textThreadChannel = await this.getChannel(channelId);
14580
+ let textChannel;
14581
+ if (textThreadChannel instanceof import_discord7.ThreadChannel) {
14582
+ const parent = textThreadChannel.parent;
14583
+ if (!parent || !(parent instanceof import_discord7.BaseGuildTextChannel) && !(parent instanceof import_discord7.ThreadOnlyChannel)) {
14584
+ throw new Error("Targeted channel parent is not a BaseGuildTextChannel or ThreadOnlyChannel");
14585
+ }
14586
+ textChannel = parent;
14587
+ } else {
14588
+ textChannel = textThreadChannel;
14589
+ }
14576
14590
  const webhooks = await textChannel.fetchWebhooks();
14577
- this.webhook = webhooks.find((h3) => h3.name === this.name && h3.owner?.id == this.client.user?.id) ?? await textChannel.createWebhook({
14591
+ this.webhook = webhooks.find(
14592
+ (h3) => h3.name === this.name && h3.owner?.id === this.client.user?.id
14593
+ ) ?? await textChannel.createWebhook({
14578
14594
  name: this.name,
14579
14595
  avatar: await this.getAvatar(),
14580
14596
  reason: "Auto-created by WebhookManager"
@@ -14598,6 +14614,10 @@ var WebhookManager = class {
14598
14614
  } else {
14599
14615
  options.content = String(content);
14600
14616
  }
14617
+ const channelType = await this.getChannel(channelId);
14618
+ if (channelType instanceof import_discord7.ThreadChannel) {
14619
+ options.threadId = channelId;
14620
+ }
14601
14621
  try {
14602
14622
  return await webhook.send(options);
14603
14623
  } catch (error) {
@@ -16132,7 +16152,7 @@ var SimpleMutex = class {
16132
16152
  // package.json
16133
16153
  var package_default = {
16134
16154
  name: "@spatulox/simplediscordbot",
16135
- version: "2.0.0",
16155
+ version: "2.0.2",
16136
16156
  author: "Spatulox",
16137
16157
  description: "Simple discord bot framework to set up a bot under 30 secondes",
16138
16158
  exports: {
package/dist/index.mjs CHANGED
@@ -14528,7 +14528,10 @@ var FileManager = class {
14528
14528
 
14529
14529
  // src/manager/messages/WebhookManager.ts
14530
14530
  import {
14531
- TextChannel as TextChannel3
14531
+ BaseGuildTextChannel,
14532
+ TextChannel as TextChannel3,
14533
+ ThreadChannel as ThreadChannel2,
14534
+ ThreadOnlyChannel
14532
14535
  } from "discord.js";
14533
14536
  import { readFile } from "fs/promises";
14534
14537
  import { resolve } from "path";
@@ -14555,22 +14558,38 @@ var WebhookManager = class {
14555
14558
  /**
14556
14559
  * Récupère le channel à partir de l'ID ou utilise directement si TextChannel/ThreadChannel
14557
14560
  */
14558
- async getTextChannel(channelId) {
14561
+ async getChannel(channelId) {
14559
14562
  const channel = await this.client.channels.fetch(channelId);
14560
- if (!channel || !(channel instanceof TextChannel3)) {
14561
- throw new Error(`Channel ${channelId} is not a TextChannel`);
14563
+ if (!channel) {
14564
+ throw new Error(`Channel ${channelId} not found`);
14565
+ }
14566
+ if (!(channel instanceof TextChannel3) && !(channel instanceof ThreadChannel2)) {
14567
+ throw new Error(`Channel ${channelId} is not a TextChannel nor a ThreadChannel`);
14562
14568
  }
14563
14569
  return channel;
14564
14570
  }
14565
14571
  /**
14566
14572
  * Get or create webhook (lazy initialization)
14573
+ * Create the webhook in the parent channel if it's in a thread
14567
14574
  */
14568
14575
  async getWebhook(channelId) {
14569
14576
  if (this.webhook) return this.webhook;
14570
14577
  try {
14571
- const textChannel = await this.getTextChannel(channelId);
14578
+ const textThreadChannel = await this.getChannel(channelId);
14579
+ let textChannel;
14580
+ if (textThreadChannel instanceof ThreadChannel2) {
14581
+ const parent = textThreadChannel.parent;
14582
+ if (!parent || !(parent instanceof BaseGuildTextChannel) && !(parent instanceof ThreadOnlyChannel)) {
14583
+ throw new Error("Targeted channel parent is not a BaseGuildTextChannel or ThreadOnlyChannel");
14584
+ }
14585
+ textChannel = parent;
14586
+ } else {
14587
+ textChannel = textThreadChannel;
14588
+ }
14572
14589
  const webhooks = await textChannel.fetchWebhooks();
14573
- this.webhook = webhooks.find((h3) => h3.name === this.name && h3.owner?.id == this.client.user?.id) ?? await textChannel.createWebhook({
14590
+ this.webhook = webhooks.find(
14591
+ (h3) => h3.name === this.name && h3.owner?.id === this.client.user?.id
14592
+ ) ?? await textChannel.createWebhook({
14574
14593
  name: this.name,
14575
14594
  avatar: await this.getAvatar(),
14576
14595
  reason: "Auto-created by WebhookManager"
@@ -14594,6 +14613,10 @@ var WebhookManager = class {
14594
14613
  } else {
14595
14614
  options.content = String(content);
14596
14615
  }
14616
+ const channelType = await this.getChannel(channelId);
14617
+ if (channelType instanceof ThreadChannel2) {
14618
+ options.threadId = channelId;
14619
+ }
14597
14620
  try {
14598
14621
  return await webhook.send(options);
14599
14622
  } catch (error) {
@@ -16151,7 +16174,7 @@ var SimpleMutex = class {
16151
16174
  // package.json
16152
16175
  var package_default = {
16153
16176
  name: "@spatulox/simplediscordbot",
16154
- version: "2.0.0",
16177
+ version: "2.0.2",
16155
16178
  author: "Spatulox",
16156
16179
  description: "Simple discord bot framework to set up a bot under 30 secondes",
16157
16180
  exports: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spatulox/simplediscordbot",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "author": "Spatulox",
5
5
  "description": "Simple discord bot framework to set up a bot under 30 secondes",
6
6
  "exports": {