@spatulox/simplediscordbot 5.0.0 → 5.1.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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Changelog
2
2
  Date format : dd/mm/yyyy
3
3
 
4
+ ### 19/11/2026 - 5.1.0
5
+ - Add :
6
+ - `BotConfig.catchUnhandledRejections` (default `false`) : the unhandled promise rejections of the process are logged with `Bot.log.error` instead of crashing it
7
+ - The client errors (`Events.Error`) are logged with `Bot.log.error` (with the stack trace), an unhandled `error` event no longer crashes the process
8
+ - Fix :
9
+ - `WebhookManager` can send in the text chat of voice and stage channels, and in announcement channels : they threw `is not a TextChannel nor a ThreadChannel`
10
+
4
11
  ### 14/10/2026 - 5.0.0
5
12
  - Breaking :
6
13
  - `BotConfig.botName` is removed : the bot name is read from the Discord account (`client.user.displayName`) once the client is ready. Remove `botName` from your config
package/README.md CHANGED
@@ -62,7 +62,8 @@ const config: BotConfig = {
62
62
  error: {channelId: "YOUR_LOG_CHANNEL_ID", console: true, discord: true},
63
63
  warn: {channelId: "YOUR_LOG_CHANNEL_ID", console: true, discord: true},
64
64
  debug: {channelId: "YOUR_LOG_CHANNEL_ID", console: true, discord: false},
65
- }
65
+ },
66
+ catchUnhandledRejections: true, // Log the unhandled promise rejections instead of crashing (default false)
66
67
  };
67
68
 
68
69
  const bot = new Bot(client, config);
package/dist/index.d.mts CHANGED
@@ -154,6 +154,10 @@ declare enum SimpleColor {
154
154
  type BotConfig = {
155
155
  defaultSimpleColor?: number | SimpleColor;
156
156
  log?: ConfigLog;
157
+ /**
158
+ * Log the unhandled promise rejections of the whole process with Bot.log.error instead of crashing (default false)
159
+ */
160
+ catchUnhandledRejections?: boolean;
157
161
  };
158
162
  type RandomBotActivity = {
159
163
  type: ActivityType;
@@ -168,6 +172,7 @@ declare class Bot {
168
172
  private static _config;
169
173
  private static _botName;
170
174
  private static randomActivityInterval;
175
+ private static unhandledRejectionListening;
171
176
  get config(): BotConfig;
172
177
  get client(): Client;
173
178
  get botName(): string;
@@ -180,6 +185,7 @@ declare class Bot {
180
185
  readonly started: Promise<boolean>;
181
186
  constructor(client: Client, config?: BotConfig);
182
187
  login(maxTries?: number): Promise<boolean>;
188
+ private static formatError;
183
189
  static setActivity(message: string, type: ActivityType): void;
184
190
  static setRandomActivity(randomActivity: RandomBotActivity, intervalMs?: number | null): void;
185
191
  /**
@@ -264,7 +270,7 @@ declare class WebhookManager {
264
270
  constructor(client: Client, name: string, avatarPathOrUrl?: string | undefined);
265
271
  private getAvatar;
266
272
  /**
267
- * Récupère le channel à partir de l'ID ou utilise directement si TextChannel/ThreadChannel
273
+ * Fetch the targeted channel, which must be able to receive a webhook message
268
274
  */
269
275
  private getChannel;
270
276
  /**
package/dist/index.d.ts CHANGED
@@ -154,6 +154,10 @@ declare enum SimpleColor {
154
154
  type BotConfig = {
155
155
  defaultSimpleColor?: number | SimpleColor;
156
156
  log?: ConfigLog;
157
+ /**
158
+ * Log the unhandled promise rejections of the whole process with Bot.log.error instead of crashing (default false)
159
+ */
160
+ catchUnhandledRejections?: boolean;
157
161
  };
158
162
  type RandomBotActivity = {
159
163
  type: ActivityType;
@@ -168,6 +172,7 @@ declare class Bot {
168
172
  private static _config;
169
173
  private static _botName;
170
174
  private static randomActivityInterval;
175
+ private static unhandledRejectionListening;
171
176
  get config(): BotConfig;
172
177
  get client(): Client;
173
178
  get botName(): string;
@@ -180,6 +185,7 @@ declare class Bot {
180
185
  readonly started: Promise<boolean>;
181
186
  constructor(client: Client, config?: BotConfig);
182
187
  login(maxTries?: number): Promise<boolean>;
188
+ private static formatError;
183
189
  static setActivity(message: string, type: ActivityType): void;
184
190
  static setRandomActivity(randomActivity: RandomBotActivity, intervalMs?: number | null): void;
185
191
  /**
@@ -264,7 +270,7 @@ declare class WebhookManager {
264
270
  constructor(client: Client, name: string, avatarPathOrUrl?: string | undefined);
265
271
  private getAvatar;
266
272
  /**
267
- * Récupère le channel à partir de l'ID ou utilise directement si TextChannel/ThreadChannel
273
+ * Fetch the targeted channel, which must be able to receive a webhook message
268
274
  */
269
275
  private getChannel;
270
276
  /**
package/dist/index.js CHANGED
@@ -705,7 +705,7 @@ var BotInteraction = class {
705
705
 
706
706
  // package.json
707
707
  var name = "@spatulox/simplediscordbot";
708
- var version = "4.0.2";
708
+ var version = "5.0.0";
709
709
  var author = "Spatulox";
710
710
  var description = "Simple discord bot framework to set up a bot under 30 secondes";
711
711
  var license = "MIT";
@@ -731,6 +731,7 @@ var Bot = class _Bot {
731
731
  static _config;
732
732
  static _botName = "";
733
733
  static randomActivityInterval = null;
734
+ static unhandledRejectionListening = false;
734
735
  get config() {
735
736
  return _Bot._config;
736
737
  }
@@ -767,6 +768,15 @@ var Bot = class _Bot {
767
768
  _Bot.log.info(EmbedManager.description("Bot Started"));
768
769
  }
769
770
  });
771
+ _Bot._client.on(import_discord7.Events.Error, (error) => {
772
+ _Bot.log.error(`Discord client error : ${_Bot.formatError(error)}`);
773
+ });
774
+ if (config.catchUnhandledRejections && !_Bot.unhandledRejectionListening) {
775
+ _Bot.unhandledRejectionListening = true;
776
+ process.on("unhandledRejection", (reason) => {
777
+ _Bot.log.error(`Unhandled rejection : ${_Bot.formatError(reason)}`);
778
+ });
779
+ }
770
780
  this.started = (async () => {
771
781
  import_utils4.Log.info(`Using discord.js version: ${import_discord7.version}`);
772
782
  import_utils4.Log.info(`Using simplediscordbot version: ${SimpleDiscordBotInfo.version}`);
@@ -796,6 +806,9 @@ var Bot = class _Bot {
796
806
  import_utils4.Log.error(`Impossible to connect the bot after ${maxTries} attempts`);
797
807
  return false;
798
808
  }
809
+ static formatError(error) {
810
+ return error instanceof Error ? error.stack ?? error.message : String(error);
811
+ }
799
812
  static setActivity(message, type) {
800
813
  if (_Bot._client.user) {
801
814
  _Bot._client.user.setActivity({ name: message, type });
@@ -867,15 +880,15 @@ var WebhookManager = class {
867
880
  }
868
881
  }
869
882
  /**
870
- * Récupère le channel à partir de l'ID ou utilise directement si TextChannel/ThreadChannel
883
+ * Fetch the targeted channel, which must be able to receive a webhook message
871
884
  */
872
885
  async getChannel(channelId) {
873
886
  const channel = await this.client.channels.fetch(channelId);
874
887
  if (!channel) {
875
888
  throw new Error(`Channel ${channelId} not found`);
876
889
  }
877
- if (!(channel instanceof import_discord8.TextChannel) && !(channel instanceof import_discord8.ThreadChannel)) {
878
- throw new Error(`Channel ${channelId} is not a TextChannel nor a ThreadChannel`);
890
+ if (!(channel instanceof import_discord8.BaseGuildTextChannel) && !(channel instanceof import_discord8.BaseGuildVoiceChannel) && !(channel instanceof import_discord8.ThreadChannel)) {
891
+ throw new Error(`Channel ${channelId} is not a text, voice or thread channel`);
879
892
  }
880
893
  return channel;
881
894
  }
package/dist/index.mjs CHANGED
@@ -684,7 +684,7 @@ var BotInteraction = class {
684
684
 
685
685
  // package.json
686
686
  var name = "@spatulox/simplediscordbot";
687
- var version = "4.0.2";
687
+ var version = "5.0.0";
688
688
  var author = "Spatulox";
689
689
  var description = "Simple discord bot framework to set up a bot under 30 secondes";
690
690
  var license = "MIT";
@@ -710,6 +710,7 @@ var Bot = class _Bot {
710
710
  static _config;
711
711
  static _botName = "";
712
712
  static randomActivityInterval = null;
713
+ static unhandledRejectionListening = false;
713
714
  get config() {
714
715
  return _Bot._config;
715
716
  }
@@ -746,6 +747,15 @@ var Bot = class _Bot {
746
747
  _Bot.log.info(EmbedManager.description("Bot Started"));
747
748
  }
748
749
  });
750
+ _Bot._client.on(Events.Error, (error) => {
751
+ _Bot.log.error(`Discord client error : ${_Bot.formatError(error)}`);
752
+ });
753
+ if (config.catchUnhandledRejections && !_Bot.unhandledRejectionListening) {
754
+ _Bot.unhandledRejectionListening = true;
755
+ process.on("unhandledRejection", (reason) => {
756
+ _Bot.log.error(`Unhandled rejection : ${_Bot.formatError(reason)}`);
757
+ });
758
+ }
749
759
  this.started = (async () => {
750
760
  Log3.info(`Using discord.js version: ${version2}`);
751
761
  Log3.info(`Using simplediscordbot version: ${SimpleDiscordBotInfo.version}`);
@@ -775,6 +785,9 @@ var Bot = class _Bot {
775
785
  Log3.error(`Impossible to connect the bot after ${maxTries} attempts`);
776
786
  return false;
777
787
  }
788
+ static formatError(error) {
789
+ return error instanceof Error ? error.stack ?? error.message : String(error);
790
+ }
778
791
  static setActivity(message, type) {
779
792
  if (_Bot._client.user) {
780
793
  _Bot._client.user.setActivity({ name: message, type });
@@ -820,7 +833,7 @@ import { CacheManager } from "@spatulox/utils";
820
833
  // src/manager/messages/WebhookManager.ts
821
834
  import {
822
835
  BaseGuildTextChannel,
823
- TextChannel as TextChannel3,
836
+ BaseGuildVoiceChannel,
824
837
  ThreadChannel as ThreadChannel2,
825
838
  ThreadOnlyChannel
826
839
  } from "discord.js";
@@ -851,15 +864,15 @@ var WebhookManager = class {
851
864
  }
852
865
  }
853
866
  /**
854
- * Récupère le channel à partir de l'ID ou utilise directement si TextChannel/ThreadChannel
867
+ * Fetch the targeted channel, which must be able to receive a webhook message
855
868
  */
856
869
  async getChannel(channelId) {
857
870
  const channel = await this.client.channels.fetch(channelId);
858
871
  if (!channel) {
859
872
  throw new Error(`Channel ${channelId} not found`);
860
873
  }
861
- if (!(channel instanceof TextChannel3) && !(channel instanceof ThreadChannel2)) {
862
- throw new Error(`Channel ${channelId} is not a TextChannel nor a ThreadChannel`);
874
+ if (!(channel instanceof BaseGuildTextChannel) && !(channel instanceof BaseGuildVoiceChannel) && !(channel instanceof ThreadChannel2)) {
875
+ throw new Error(`Channel ${channelId} is not a text, voice or thread channel`);
863
876
  }
864
877
  return channel;
865
878
  }
@@ -1688,16 +1701,16 @@ var StageChannelManager = class extends GuildChannelManager {
1688
1701
  };
1689
1702
 
1690
1703
  // src/manager/guild/ChannelManager/GuildTextChannelManager.ts
1691
- import { TextChannel as TextChannel4, ChannelType as ChannelType5 } from "discord.js";
1704
+ import { TextChannel as TextChannel3, ChannelType as ChannelType5 } from "discord.js";
1692
1705
  import { Log as Log13 } from "@spatulox/utils";
1693
1706
  var GuildTextChannelManager = class extends GuildChannelManager {
1694
1707
  static async findInGuild(guildId, channelId) {
1695
1708
  const channel = await super.findInGuild(guildId, channelId);
1696
- return channel instanceof TextChannel4 ? channel : null;
1709
+ return channel instanceof TextChannel3 ? channel : null;
1697
1710
  }
1698
1711
  static async find(channelId) {
1699
1712
  const channel = await super.find(channelId);
1700
- return channel instanceof TextChannel4 ? channel : null;
1713
+ return channel instanceof TextChannel3 ? channel : null;
1701
1714
  }
1702
1715
  static findAll(guildId) {
1703
1716
  const guild = Bot.client.guilds.cache.get(guildId);
@@ -1705,7 +1718,7 @@ var GuildTextChannelManager = class extends GuildChannelManager {
1705
1718
  Log13.warn(`Guild ${guildId} not found`);
1706
1719
  return [];
1707
1720
  }
1708
- return Array.from(guild.channels.cache.values()).filter((c) => c instanceof TextChannel4);
1721
+ return Array.from(guild.channels.cache.values()).filter((c) => c instanceof TextChannel3);
1709
1722
  }
1710
1723
  static async create(guildId, name2, options) {
1711
1724
  return await super._create(guildId, {
@@ -1719,7 +1732,7 @@ var GuildTextChannelManager = class extends GuildChannelManager {
1719
1732
  // src/manager/guild/ChannelManager/ThreadChannelManager.ts
1720
1733
  import {
1721
1734
  NewsChannel as NewsChannel2,
1722
- TextChannel as TextChannel5
1735
+ TextChannel as TextChannel4
1723
1736
  } from "discord.js";
1724
1737
  var ThreadChannelManager = class {
1725
1738
  static async findInGuild(guildId, channelId) {
@@ -1736,7 +1749,7 @@ var ThreadChannelManager = class {
1736
1749
  }
1737
1750
  static async createFromChannel(parentId, options) {
1738
1751
  const channel = await GuildChannelManager.find(parentId);
1739
- if (!(channel instanceof TextChannel5) && !(channel instanceof NewsChannel2)) {
1752
+ if (!(channel instanceof TextChannel4) && !(channel instanceof NewsChannel2)) {
1740
1753
  throw new Error("Parent must be a text or announcement channel");
1741
1754
  }
1742
1755
  const thread = await channel.threads.create(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spatulox/simplediscordbot",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "author": "Spatulox",
5
5
  "description": "Simple discord bot framework to set up a bot under 30 secondes",
6
6
  "main": "./dist/index.js",