@spatulox/simplediscordbot 2.0.1 → 2.0.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/index.js CHANGED
@@ -14561,8 +14561,11 @@ var WebhookManager = class {
14561
14561
  */
14562
14562
  async getTextChannel(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
  }
@@ -14572,9 +14575,21 @@ var WebhookManager = class {
14572
14575
  async getWebhook(channelId) {
14573
14576
  if (this.webhook) return this.webhook;
14574
14577
  try {
14575
- const textChannel = await this.getTextChannel(channelId);
14578
+ const textThreadChannel = await this.getTextChannel(channelId);
14579
+ let textChannel;
14580
+ if (textThreadChannel instanceof import_discord7.ThreadChannel) {
14581
+ const parent = textThreadChannel.parent;
14582
+ if (!parent || !(parent instanceof import_discord7.BaseGuildTextChannel)) {
14583
+ throw new Error("Targeted channel parent is not a BaseGuildTextChannel");
14584
+ }
14585
+ textChannel = parent;
14586
+ } else {
14587
+ textChannel = textThreadChannel;
14588
+ }
14576
14589
  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({
14590
+ this.webhook = webhooks.find(
14591
+ (h3) => h3.name === this.name && h3.owner?.id === this.client.user?.id
14592
+ ) ?? await textChannel.createWebhook({
14578
14593
  name: this.name,
14579
14594
  avatar: await this.getAvatar(),
14580
14595
  reason: "Auto-created by WebhookManager"
@@ -16132,7 +16147,7 @@ var SimpleMutex = class {
16132
16147
  // package.json
16133
16148
  var package_default = {
16134
16149
  name: "@spatulox/simplediscordbot",
16135
- version: "2.0.0",
16150
+ version: "2.0.1",
16136
16151
  author: "Spatulox",
16137
16152
  description: "Simple discord bot framework to set up a bot under 30 secondes",
16138
16153
  exports: {
package/dist/index.mjs CHANGED
@@ -14528,7 +14528,9 @@ 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
14532
14534
  } from "discord.js";
14533
14535
  import { readFile } from "fs/promises";
14534
14536
  import { resolve } from "path";
@@ -14557,8 +14559,11 @@ var WebhookManager = class {
14557
14559
  */
14558
14560
  async getTextChannel(channelId) {
14559
14561
  const channel = await this.client.channels.fetch(channelId);
14560
- if (!channel || !(channel instanceof TextChannel3)) {
14561
- throw new Error(`Channel ${channelId} is not a TextChannel`);
14562
+ if (!channel) {
14563
+ throw new Error(`Channel ${channelId} not found`);
14564
+ }
14565
+ if (!(channel instanceof TextChannel3) && !(channel instanceof ThreadChannel2)) {
14566
+ throw new Error(`Channel ${channelId} is not a TextChannel nor a ThreadChannel`);
14562
14567
  }
14563
14568
  return channel;
14564
14569
  }
@@ -14568,9 +14573,21 @@ var WebhookManager = class {
14568
14573
  async getWebhook(channelId) {
14569
14574
  if (this.webhook) return this.webhook;
14570
14575
  try {
14571
- const textChannel = await this.getTextChannel(channelId);
14576
+ const textThreadChannel = await this.getTextChannel(channelId);
14577
+ let textChannel;
14578
+ if (textThreadChannel instanceof ThreadChannel2) {
14579
+ const parent = textThreadChannel.parent;
14580
+ if (!parent || !(parent instanceof BaseGuildTextChannel)) {
14581
+ throw new Error("Targeted channel parent is not a BaseGuildTextChannel");
14582
+ }
14583
+ textChannel = parent;
14584
+ } else {
14585
+ textChannel = textThreadChannel;
14586
+ }
14572
14587
  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({
14588
+ this.webhook = webhooks.find(
14589
+ (h3) => h3.name === this.name && h3.owner?.id === this.client.user?.id
14590
+ ) ?? await textChannel.createWebhook({
14574
14591
  name: this.name,
14575
14592
  avatar: await this.getAvatar(),
14576
14593
  reason: "Auto-created by WebhookManager"
@@ -16151,7 +16168,7 @@ var SimpleMutex = class {
16151
16168
  // package.json
16152
16169
  var package_default = {
16153
16170
  name: "@spatulox/simplediscordbot",
16154
- version: "2.0.0",
16171
+ version: "2.0.1",
16155
16172
  author: "Spatulox",
16156
16173
  description: "Simple discord bot framework to set up a bot under 30 secondes",
16157
16174
  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.2",
4
4
  "author": "Spatulox",
5
5
  "description": "Simple discord bot framework to set up a bot under 30 secondes",
6
6
  "exports": {