@fluxerjs/core 1.3.0 → 1.3.1

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/client.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { C as CacheSizeLimits, f as Client, g as ClientEventMethods, h as ClientEvents, i as ClientOptions, E as Events } from './subpath-message-b43enjDT.mjs';
1
+ export { C as CacheSizeLimits, f as Client, g as ClientEventMethods, h as ClientEvents, i as ClientOptions, E as Events } from './subpath-message-CZC4oGko.mjs';
2
2
  import 'events';
3
3
  import '@fluxerjs/rest';
4
4
  import '@fluxerjs/ws';
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { C as CacheSizeLimits, f as Client, g as ClientEventMethods, h as ClientEvents, i as ClientOptions, E as Events } from './subpath-message-b43enjDT.js';
1
+ export { C as CacheSizeLimits, f as Client, g as ClientEventMethods, h as ClientEvents, i as ClientOptions, E as Events } from './subpath-message-CZC4oGko.js';
2
2
  import 'events';
3
3
  import '@fluxerjs/rest';
4
4
  import '@fluxerjs/ws';
package/dist/client.js CHANGED
@@ -2952,9 +2952,12 @@ var ChatInputCommandInteraction = class extends BaseInteraction {
2952
2952
  constructor(client, raw) {
2953
2953
  super(client, raw);
2954
2954
  if (raw.data?.name == null) {
2955
- throw new import_util.FluxerError("ChatInputCommandInteraction requires interaction data with a command name", {
2956
- code: import_util2.ErrorCodes.InteractionInvalidPayload
2957
- });
2955
+ throw new import_util.FluxerError(
2956
+ "ChatInputCommandInteraction requires interaction data with a command name",
2957
+ {
2958
+ code: import_util2.ErrorCodes.InteractionInvalidPayload
2959
+ }
2960
+ );
2958
2961
  }
2959
2962
  }
2960
2963
  /** Command name (e.g. `ping`). */
@@ -3543,6 +3546,11 @@ var Client = class extends import_events3.EventEmitter {
3543
3546
  _pendingGuildIds = null;
3544
3547
  /** Timeout for guild stream when READY has no guilds (gateway sends only GUILD_CREATE). Cleared in finally. */
3545
3548
  _guildStreamSettleTimeout = null;
3549
+ /**
3550
+ * When waitForGuilds delays Ready, gateway dispatches (except GUILD_CREATE) are queued and replayed after Ready.
3551
+ * Ensures user handlers that assume post-Ready setup (e.g. DB in Ready) do not run during the guild sync window.
3552
+ */
3553
+ _deferredGatewayDispatches = [];
3546
3554
  /** Per-channel message cache (channelId -> messageId -> APIMessage). Used when options.cache.messages > 0. */
3547
3555
  _messageCaches = null;
3548
3556
  on(event, listener) {
@@ -3740,13 +3748,32 @@ var Client = class extends import_events3.EventEmitter {
3740
3748
  sendToGateway(shardId, payload) {
3741
3749
  this.ws.send(shardId, payload);
3742
3750
  }
3751
+ /**
3752
+ * While {@link ClientOptions.waitForGuilds} delays Ready, defer user-facing dispatch handling until Ready fires.
3753
+ * GUILD_CREATE must still run immediately so guild cache and {@link Client._onGuildReceived} can finish the handshake.
3754
+ */
3755
+ _shouldDeferGatewayDispatchUntilReady(payload) {
3756
+ if (this.options.waitForGuilds !== true || this.readyAt !== null) return false;
3757
+ if (payload.op !== 0 || !payload.t) return false;
3758
+ if (payload.t === "GUILD_CREATE") return false;
3759
+ return true;
3760
+ }
3743
3761
  /**
3744
3762
  * Run gateway event handlers. By default (see {@link ClientOptions.gatewayDeferHandlers}) work is deferred to the next
3745
3763
  * macrotask so user code does not block the WebSocket `message` callback.
3746
3764
  */
3747
3765
  handleDispatch(payload) {
3748
3766
  if (payload.op !== 0 || !payload.t) return Promise.resolve();
3749
- const { t: event, d } = payload;
3767
+ if (this._shouldDeferGatewayDispatchUntilReady(payload)) {
3768
+ this._deferredGatewayDispatches.push(payload);
3769
+ return Promise.resolve();
3770
+ }
3771
+ return this._dispatchGatewayPayload(payload);
3772
+ }
3773
+ _dispatchGatewayPayload(payload) {
3774
+ const event = payload.t;
3775
+ if (!event) return Promise.resolve();
3776
+ const { d } = payload;
3750
3777
  const handler = eventHandlers.get(event);
3751
3778
  if (!handler) return Promise.resolve();
3752
3779
  const run = async () => {
@@ -3770,6 +3797,15 @@ var Client = class extends import_events3.EventEmitter {
3770
3797
  }
3771
3798
  });
3772
3799
  }
3800
+ async _flushDeferredGatewayDispatches() {
3801
+ while (this._deferredGatewayDispatches.length > 0) {
3802
+ const batch = this._deferredGatewayDispatches;
3803
+ this._deferredGatewayDispatches = [];
3804
+ for (const p of batch) {
3805
+ await this._dispatchGatewayPayload(p);
3806
+ }
3807
+ }
3808
+ }
3773
3809
  /**
3774
3810
  * Connect to the Fluxer gateway and authenticate.
3775
3811
  * @param token - Bot token (e.g. from FLUXER_BOT_TOKEN)
@@ -3868,6 +3904,9 @@ var Client = class extends import_events3.EventEmitter {
3868
3904
  this._pendingGuildIds = null;
3869
3905
  this.readyAt = /* @__PURE__ */ new Date();
3870
3906
  this.emit(Events.Ready);
3907
+ void this._flushDeferredGatewayDispatches().catch(
3908
+ (err) => this.emit(Events.Error, err instanceof Error ? err : new Error(String(err)))
3909
+ );
3871
3910
  }
3872
3911
  /**
3873
3912
  * Called by GUILD_CREATE handler when waitForGuilds is enabled.
@@ -3885,6 +3924,7 @@ var Client = class extends import_events3.EventEmitter {
3885
3924
  clearTimeout(this._guildStreamSettleTimeout);
3886
3925
  this._guildStreamSettleTimeout = null;
3887
3926
  }
3927
+ this._deferredGatewayDispatches = [];
3888
3928
  if (this._ws) {
3889
3929
  this._ws.destroy();
3890
3930
  this._ws = null;
package/dist/client.mjs CHANGED
@@ -2940,9 +2940,12 @@ var ChatInputCommandInteraction = class extends BaseInteraction {
2940
2940
  constructor(client, raw) {
2941
2941
  super(client, raw);
2942
2942
  if (raw.data?.name == null) {
2943
- throw new FluxerError("ChatInputCommandInteraction requires interaction data with a command name", {
2944
- code: ErrorCodes.InteractionInvalidPayload
2945
- });
2943
+ throw new FluxerError(
2944
+ "ChatInputCommandInteraction requires interaction data with a command name",
2945
+ {
2946
+ code: ErrorCodes.InteractionInvalidPayload
2947
+ }
2948
+ );
2946
2949
  }
2947
2950
  }
2948
2951
  /** Command name (e.g. `ping`). */
@@ -3531,6 +3534,11 @@ var Client = class extends EventEmitter3 {
3531
3534
  _pendingGuildIds = null;
3532
3535
  /** Timeout for guild stream when READY has no guilds (gateway sends only GUILD_CREATE). Cleared in finally. */
3533
3536
  _guildStreamSettleTimeout = null;
3537
+ /**
3538
+ * When waitForGuilds delays Ready, gateway dispatches (except GUILD_CREATE) are queued and replayed after Ready.
3539
+ * Ensures user handlers that assume post-Ready setup (e.g. DB in Ready) do not run during the guild sync window.
3540
+ */
3541
+ _deferredGatewayDispatches = [];
3534
3542
  /** Per-channel message cache (channelId -> messageId -> APIMessage). Used when options.cache.messages > 0. */
3535
3543
  _messageCaches = null;
3536
3544
  on(event, listener) {
@@ -3728,13 +3736,32 @@ var Client = class extends EventEmitter3 {
3728
3736
  sendToGateway(shardId, payload) {
3729
3737
  this.ws.send(shardId, payload);
3730
3738
  }
3739
+ /**
3740
+ * While {@link ClientOptions.waitForGuilds} delays Ready, defer user-facing dispatch handling until Ready fires.
3741
+ * GUILD_CREATE must still run immediately so guild cache and {@link Client._onGuildReceived} can finish the handshake.
3742
+ */
3743
+ _shouldDeferGatewayDispatchUntilReady(payload) {
3744
+ if (this.options.waitForGuilds !== true || this.readyAt !== null) return false;
3745
+ if (payload.op !== 0 || !payload.t) return false;
3746
+ if (payload.t === "GUILD_CREATE") return false;
3747
+ return true;
3748
+ }
3731
3749
  /**
3732
3750
  * Run gateway event handlers. By default (see {@link ClientOptions.gatewayDeferHandlers}) work is deferred to the next
3733
3751
  * macrotask so user code does not block the WebSocket `message` callback.
3734
3752
  */
3735
3753
  handleDispatch(payload) {
3736
3754
  if (payload.op !== 0 || !payload.t) return Promise.resolve();
3737
- const { t: event, d } = payload;
3755
+ if (this._shouldDeferGatewayDispatchUntilReady(payload)) {
3756
+ this._deferredGatewayDispatches.push(payload);
3757
+ return Promise.resolve();
3758
+ }
3759
+ return this._dispatchGatewayPayload(payload);
3760
+ }
3761
+ _dispatchGatewayPayload(payload) {
3762
+ const event = payload.t;
3763
+ if (!event) return Promise.resolve();
3764
+ const { d } = payload;
3738
3765
  const handler = eventHandlers.get(event);
3739
3766
  if (!handler) return Promise.resolve();
3740
3767
  const run = async () => {
@@ -3758,6 +3785,15 @@ var Client = class extends EventEmitter3 {
3758
3785
  }
3759
3786
  });
3760
3787
  }
3788
+ async _flushDeferredGatewayDispatches() {
3789
+ while (this._deferredGatewayDispatches.length > 0) {
3790
+ const batch = this._deferredGatewayDispatches;
3791
+ this._deferredGatewayDispatches = [];
3792
+ for (const p of batch) {
3793
+ await this._dispatchGatewayPayload(p);
3794
+ }
3795
+ }
3796
+ }
3761
3797
  /**
3762
3798
  * Connect to the Fluxer gateway and authenticate.
3763
3799
  * @param token - Bot token (e.g. from FLUXER_BOT_TOKEN)
@@ -3856,6 +3892,9 @@ var Client = class extends EventEmitter3 {
3856
3892
  this._pendingGuildIds = null;
3857
3893
  this.readyAt = /* @__PURE__ */ new Date();
3858
3894
  this.emit(Events.Ready);
3895
+ void this._flushDeferredGatewayDispatches().catch(
3896
+ (err) => this.emit(Events.Error, err instanceof Error ? err : new Error(String(err)))
3897
+ );
3859
3898
  }
3860
3899
  /**
3861
3900
  * Called by GUILD_CREATE handler when waitForGuilds is enabled.
@@ -3873,6 +3912,7 @@ var Client = class extends EventEmitter3 {
3873
3912
  clearTimeout(this._guildStreamSettleTimeout);
3874
3913
  this._guildStreamSettleTimeout = null;
3875
3914
  }
3915
+ this._deferredGatewayDispatches = [];
3876
3916
  if (this._ws) {
3877
3917
  this._ws.destroy();
3878
3918
  this._ws = null;
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AnyInteraction, B as Base, a as BaseInteraction, C as CacheSizeLimits, b as CategoryChannel, c as Channel, d as ChannelManager, e as ChatInputCommandInteraction, f as Client, g as ClientEventMethods, h as ClientEvents, i as ClientOptions, j as ClientUser, k as CollectedReaction, D as DMChannel, E as Events, F as FetchedUserWithProfile, G as Guild, l as GuildBan, m as GuildChannel, n as GuildEmoji, o as GuildMember, p as GuildMemberManager, q as GuildMemberRoleManager, r as GuildSticker, I as Invite, L as LinkChannel, M as Message, s as MessageCollector, t as MessageCollectorEndReason, u as MessageCollectorOptions, v as MessageEditOptions, w as MessageManager, x as MessageReaction, y as MessageSendOptions, P as PartialMessage, R as ReactionCollector, z as ReactionCollectorEndReason, H as ReactionCollectorOptions, J as ReplyOptions, K as Role, N as RoleResolvable, T as TextChannel, U as User, O as UsersManager, V as VoiceChannel, W as Webhook, Q as WebhookMessageEditOptions, S as WebhookSendOptions, X as createInteraction, Y as isChatInputCommandInteraction } from './subpath-message-b43enjDT.mjs';
1
+ export { A as AnyInteraction, B as Base, a as BaseInteraction, C as CacheSizeLimits, b as CategoryChannel, c as Channel, d as ChannelManager, e as ChatInputCommandInteraction, f as Client, g as ClientEventMethods, h as ClientEvents, i as ClientOptions, j as ClientUser, k as CollectedReaction, D as DMChannel, E as Events, F as FetchedUserWithProfile, G as Guild, l as GuildBan, m as GuildChannel, n as GuildEmoji, o as GuildMember, p as GuildMemberManager, q as GuildMemberRoleManager, r as GuildSticker, I as Invite, L as LinkChannel, M as Message, s as MessageCollector, t as MessageCollectorEndReason, u as MessageCollectorOptions, v as MessageEditOptions, w as MessageManager, x as MessageReaction, y as MessageSendOptions, P as PartialMessage, R as ReactionCollector, z as ReactionCollectorEndReason, H as ReactionCollectorOptions, J as ReplyOptions, K as Role, N as RoleResolvable, T as TextChannel, U as User, O as UsersManager, V as VoiceChannel, W as Webhook, Q as WebhookMessageEditOptions, S as WebhookSendOptions, X as createInteraction, Y as isChatInputCommandInteraction } from './subpath-message-CZC4oGko.mjs';
2
2
  export { ErrorCodes, FluxerError, FluxerErrorOptions, PermissionFlags, PermissionResolvable, PermissionString, PermissionsBitField, UserFlagsBitField, UserFlagsBits, UserFlagsResolvable, UserFlagsString, parsePrefixCommand, parseUserMention, resolvePermissionsToBitfield, resolveTenorToImageUrl } from '@fluxerjs/util';
3
3
  export { AttachmentBuilder, EmbedBuilder, MessagePayload } from '@fluxerjs/builders';
4
4
  export { GatewayOpcodes, MessageAttachmentFlags, Routes } from '@fluxerjs/types';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AnyInteraction, B as Base, a as BaseInteraction, C as CacheSizeLimits, b as CategoryChannel, c as Channel, d as ChannelManager, e as ChatInputCommandInteraction, f as Client, g as ClientEventMethods, h as ClientEvents, i as ClientOptions, j as ClientUser, k as CollectedReaction, D as DMChannel, E as Events, F as FetchedUserWithProfile, G as Guild, l as GuildBan, m as GuildChannel, n as GuildEmoji, o as GuildMember, p as GuildMemberManager, q as GuildMemberRoleManager, r as GuildSticker, I as Invite, L as LinkChannel, M as Message, s as MessageCollector, t as MessageCollectorEndReason, u as MessageCollectorOptions, v as MessageEditOptions, w as MessageManager, x as MessageReaction, y as MessageSendOptions, P as PartialMessage, R as ReactionCollector, z as ReactionCollectorEndReason, H as ReactionCollectorOptions, J as ReplyOptions, K as Role, N as RoleResolvable, T as TextChannel, U as User, O as UsersManager, V as VoiceChannel, W as Webhook, Q as WebhookMessageEditOptions, S as WebhookSendOptions, X as createInteraction, Y as isChatInputCommandInteraction } from './subpath-message-b43enjDT.js';
1
+ export { A as AnyInteraction, B as Base, a as BaseInteraction, C as CacheSizeLimits, b as CategoryChannel, c as Channel, d as ChannelManager, e as ChatInputCommandInteraction, f as Client, g as ClientEventMethods, h as ClientEvents, i as ClientOptions, j as ClientUser, k as CollectedReaction, D as DMChannel, E as Events, F as FetchedUserWithProfile, G as Guild, l as GuildBan, m as GuildChannel, n as GuildEmoji, o as GuildMember, p as GuildMemberManager, q as GuildMemberRoleManager, r as GuildSticker, I as Invite, L as LinkChannel, M as Message, s as MessageCollector, t as MessageCollectorEndReason, u as MessageCollectorOptions, v as MessageEditOptions, w as MessageManager, x as MessageReaction, y as MessageSendOptions, P as PartialMessage, R as ReactionCollector, z as ReactionCollectorEndReason, H as ReactionCollectorOptions, J as ReplyOptions, K as Role, N as RoleResolvable, T as TextChannel, U as User, O as UsersManager, V as VoiceChannel, W as Webhook, Q as WebhookMessageEditOptions, S as WebhookSendOptions, X as createInteraction, Y as isChatInputCommandInteraction } from './subpath-message-CZC4oGko.js';
2
2
  export { ErrorCodes, FluxerError, FluxerErrorOptions, PermissionFlags, PermissionResolvable, PermissionString, PermissionsBitField, UserFlagsBitField, UserFlagsBits, UserFlagsResolvable, UserFlagsString, parsePrefixCommand, parseUserMention, resolvePermissionsToBitfield, resolveTenorToImageUrl } from '@fluxerjs/util';
3
3
  export { AttachmentBuilder, EmbedBuilder, MessagePayload } from '@fluxerjs/builders';
4
4
  export { GatewayOpcodes, MessageAttachmentFlags, Routes } from '@fluxerjs/types';
package/dist/index.js CHANGED
@@ -3016,9 +3016,12 @@ var ChatInputCommandInteraction = class extends BaseInteraction {
3016
3016
  constructor(client, raw) {
3017
3017
  super(client, raw);
3018
3018
  if (raw.data?.name == null) {
3019
- throw new import_util.FluxerError("ChatInputCommandInteraction requires interaction data with a command name", {
3020
- code: import_util2.ErrorCodes.InteractionInvalidPayload
3021
- });
3019
+ throw new import_util.FluxerError(
3020
+ "ChatInputCommandInteraction requires interaction data with a command name",
3021
+ {
3022
+ code: import_util2.ErrorCodes.InteractionInvalidPayload
3023
+ }
3024
+ );
3022
3025
  }
3023
3026
  }
3024
3027
  /** Command name (e.g. `ping`). */
@@ -3610,6 +3613,11 @@ var Client = class extends import_events3.EventEmitter {
3610
3613
  _pendingGuildIds = null;
3611
3614
  /** Timeout for guild stream when READY has no guilds (gateway sends only GUILD_CREATE). Cleared in finally. */
3612
3615
  _guildStreamSettleTimeout = null;
3616
+ /**
3617
+ * When waitForGuilds delays Ready, gateway dispatches (except GUILD_CREATE) are queued and replayed after Ready.
3618
+ * Ensures user handlers that assume post-Ready setup (e.g. DB in Ready) do not run during the guild sync window.
3619
+ */
3620
+ _deferredGatewayDispatches = [];
3613
3621
  /** Per-channel message cache (channelId -> messageId -> APIMessage). Used when options.cache.messages > 0. */
3614
3622
  _messageCaches = null;
3615
3623
  on(event, listener) {
@@ -3807,13 +3815,32 @@ var Client = class extends import_events3.EventEmitter {
3807
3815
  sendToGateway(shardId, payload) {
3808
3816
  this.ws.send(shardId, payload);
3809
3817
  }
3818
+ /**
3819
+ * While {@link ClientOptions.waitForGuilds} delays Ready, defer user-facing dispatch handling until Ready fires.
3820
+ * GUILD_CREATE must still run immediately so guild cache and {@link Client._onGuildReceived} can finish the handshake.
3821
+ */
3822
+ _shouldDeferGatewayDispatchUntilReady(payload) {
3823
+ if (this.options.waitForGuilds !== true || this.readyAt !== null) return false;
3824
+ if (payload.op !== 0 || !payload.t) return false;
3825
+ if (payload.t === "GUILD_CREATE") return false;
3826
+ return true;
3827
+ }
3810
3828
  /**
3811
3829
  * Run gateway event handlers. By default (see {@link ClientOptions.gatewayDeferHandlers}) work is deferred to the next
3812
3830
  * macrotask so user code does not block the WebSocket `message` callback.
3813
3831
  */
3814
3832
  handleDispatch(payload) {
3815
3833
  if (payload.op !== 0 || !payload.t) return Promise.resolve();
3816
- const { t: event, d } = payload;
3834
+ if (this._shouldDeferGatewayDispatchUntilReady(payload)) {
3835
+ this._deferredGatewayDispatches.push(payload);
3836
+ return Promise.resolve();
3837
+ }
3838
+ return this._dispatchGatewayPayload(payload);
3839
+ }
3840
+ _dispatchGatewayPayload(payload) {
3841
+ const event = payload.t;
3842
+ if (!event) return Promise.resolve();
3843
+ const { d } = payload;
3817
3844
  const handler = eventHandlers.get(event);
3818
3845
  if (!handler) return Promise.resolve();
3819
3846
  const run = async () => {
@@ -3837,6 +3864,15 @@ var Client = class extends import_events3.EventEmitter {
3837
3864
  }
3838
3865
  });
3839
3866
  }
3867
+ async _flushDeferredGatewayDispatches() {
3868
+ while (this._deferredGatewayDispatches.length > 0) {
3869
+ const batch = this._deferredGatewayDispatches;
3870
+ this._deferredGatewayDispatches = [];
3871
+ for (const p of batch) {
3872
+ await this._dispatchGatewayPayload(p);
3873
+ }
3874
+ }
3875
+ }
3840
3876
  /**
3841
3877
  * Connect to the Fluxer gateway and authenticate.
3842
3878
  * @param token - Bot token (e.g. from FLUXER_BOT_TOKEN)
@@ -3935,6 +3971,9 @@ var Client = class extends import_events3.EventEmitter {
3935
3971
  this._pendingGuildIds = null;
3936
3972
  this.readyAt = /* @__PURE__ */ new Date();
3937
3973
  this.emit(Events.Ready);
3974
+ void this._flushDeferredGatewayDispatches().catch(
3975
+ (err) => this.emit(Events.Error, err instanceof Error ? err : new Error(String(err)))
3976
+ );
3938
3977
  }
3939
3978
  /**
3940
3979
  * Called by GUILD_CREATE handler when waitForGuilds is enabled.
@@ -3952,6 +3991,7 @@ var Client = class extends import_events3.EventEmitter {
3952
3991
  clearTimeout(this._guildStreamSettleTimeout);
3953
3992
  this._guildStreamSettleTimeout = null;
3954
3993
  }
3994
+ this._deferredGatewayDispatches = [];
3955
3995
  if (this._ws) {
3956
3996
  this._ws.destroy();
3957
3997
  this._ws = null;
package/dist/index.mjs CHANGED
@@ -2949,9 +2949,12 @@ var ChatInputCommandInteraction = class extends BaseInteraction {
2949
2949
  constructor(client, raw) {
2950
2950
  super(client, raw);
2951
2951
  if (raw.data?.name == null) {
2952
- throw new FluxerError("ChatInputCommandInteraction requires interaction data with a command name", {
2953
- code: ErrorCodes.InteractionInvalidPayload
2954
- });
2952
+ throw new FluxerError(
2953
+ "ChatInputCommandInteraction requires interaction data with a command name",
2954
+ {
2955
+ code: ErrorCodes.InteractionInvalidPayload
2956
+ }
2957
+ );
2955
2958
  }
2956
2959
  }
2957
2960
  /** Command name (e.g. `ping`). */
@@ -3543,6 +3546,11 @@ var Client = class extends EventEmitter3 {
3543
3546
  _pendingGuildIds = null;
3544
3547
  /** Timeout for guild stream when READY has no guilds (gateway sends only GUILD_CREATE). Cleared in finally. */
3545
3548
  _guildStreamSettleTimeout = null;
3549
+ /**
3550
+ * When waitForGuilds delays Ready, gateway dispatches (except GUILD_CREATE) are queued and replayed after Ready.
3551
+ * Ensures user handlers that assume post-Ready setup (e.g. DB in Ready) do not run during the guild sync window.
3552
+ */
3553
+ _deferredGatewayDispatches = [];
3546
3554
  /** Per-channel message cache (channelId -> messageId -> APIMessage). Used when options.cache.messages > 0. */
3547
3555
  _messageCaches = null;
3548
3556
  on(event, listener) {
@@ -3740,13 +3748,32 @@ var Client = class extends EventEmitter3 {
3740
3748
  sendToGateway(shardId, payload) {
3741
3749
  this.ws.send(shardId, payload);
3742
3750
  }
3751
+ /**
3752
+ * While {@link ClientOptions.waitForGuilds} delays Ready, defer user-facing dispatch handling until Ready fires.
3753
+ * GUILD_CREATE must still run immediately so guild cache and {@link Client._onGuildReceived} can finish the handshake.
3754
+ */
3755
+ _shouldDeferGatewayDispatchUntilReady(payload) {
3756
+ if (this.options.waitForGuilds !== true || this.readyAt !== null) return false;
3757
+ if (payload.op !== 0 || !payload.t) return false;
3758
+ if (payload.t === "GUILD_CREATE") return false;
3759
+ return true;
3760
+ }
3743
3761
  /**
3744
3762
  * Run gateway event handlers. By default (see {@link ClientOptions.gatewayDeferHandlers}) work is deferred to the next
3745
3763
  * macrotask so user code does not block the WebSocket `message` callback.
3746
3764
  */
3747
3765
  handleDispatch(payload) {
3748
3766
  if (payload.op !== 0 || !payload.t) return Promise.resolve();
3749
- const { t: event, d } = payload;
3767
+ if (this._shouldDeferGatewayDispatchUntilReady(payload)) {
3768
+ this._deferredGatewayDispatches.push(payload);
3769
+ return Promise.resolve();
3770
+ }
3771
+ return this._dispatchGatewayPayload(payload);
3772
+ }
3773
+ _dispatchGatewayPayload(payload) {
3774
+ const event = payload.t;
3775
+ if (!event) return Promise.resolve();
3776
+ const { d } = payload;
3750
3777
  const handler = eventHandlers.get(event);
3751
3778
  if (!handler) return Promise.resolve();
3752
3779
  const run = async () => {
@@ -3770,6 +3797,15 @@ var Client = class extends EventEmitter3 {
3770
3797
  }
3771
3798
  });
3772
3799
  }
3800
+ async _flushDeferredGatewayDispatches() {
3801
+ while (this._deferredGatewayDispatches.length > 0) {
3802
+ const batch = this._deferredGatewayDispatches;
3803
+ this._deferredGatewayDispatches = [];
3804
+ for (const p of batch) {
3805
+ await this._dispatchGatewayPayload(p);
3806
+ }
3807
+ }
3808
+ }
3773
3809
  /**
3774
3810
  * Connect to the Fluxer gateway and authenticate.
3775
3811
  * @param token - Bot token (e.g. from FLUXER_BOT_TOKEN)
@@ -3868,6 +3904,9 @@ var Client = class extends EventEmitter3 {
3868
3904
  this._pendingGuildIds = null;
3869
3905
  this.readyAt = /* @__PURE__ */ new Date();
3870
3906
  this.emit(Events.Ready);
3907
+ void this._flushDeferredGatewayDispatches().catch(
3908
+ (err) => this.emit(Events.Error, err instanceof Error ? err : new Error(String(err)))
3909
+ );
3871
3910
  }
3872
3911
  /**
3873
3912
  * Called by GUILD_CREATE handler when waitForGuilds is enabled.
@@ -3885,6 +3924,7 @@ var Client = class extends EventEmitter3 {
3885
3924
  clearTimeout(this._guildStreamSettleTimeout);
3886
3925
  this._guildStreamSettleTimeout = null;
3887
3926
  }
3927
+ this._deferredGatewayDispatches = [];
3888
3928
  if (this._ws) {
3889
3929
  this._ws.destroy();
3890
3930
  this._ws = null;
@@ -1,4 +1,4 @@
1
- export { M as Message, v as MessageEditOptions, y as MessageSendOptions, P as PartialMessage, J as ReplyOptions } from './subpath-message-b43enjDT.mjs';
1
+ export { M as Message, v as MessageEditOptions, y as MessageSendOptions, P as PartialMessage, J as ReplyOptions } from './subpath-message-CZC4oGko.mjs';
2
2
  import 'events';
3
3
  import '@fluxerjs/rest';
4
4
  import '@fluxerjs/ws';
package/dist/message.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { M as Message, v as MessageEditOptions, y as MessageSendOptions, P as PartialMessage, J as ReplyOptions } from './subpath-message-b43enjDT.js';
1
+ export { M as Message, v as MessageEditOptions, y as MessageSendOptions, P as PartialMessage, J as ReplyOptions } from './subpath-message-CZC4oGko.js';
2
2
  import 'events';
3
3
  import '@fluxerjs/rest';
4
4
  import '@fluxerjs/ws';
@@ -1618,7 +1618,11 @@ interface ClientOptions {
1618
1618
  intents?: number;
1619
1619
  /** Suppress the warning when intents are set (Fluxer does not support intents yet). */
1620
1620
  suppressIntentWarning?: boolean;
1621
- /** When true, delay the Ready event until all guilds from READY (including unavailable) have been received via GUILD_CREATE. Default: false. */
1621
+ /**
1622
+ * When true, delay the Ready event until all guilds from READY (including unavailable) have been received via GUILD_CREATE.
1623
+ * Other gateway dispatches (e.g. MESSAGE_CREATE) are queued and delivered after Ready so handlers can rely on post-Ready setup.
1624
+ * GUILD_CREATE still runs during sync so the guild cache can finish loading. Default: false.
1625
+ */
1622
1626
  waitForGuilds?: boolean;
1623
1627
  /** Cache size limits (channels, guilds, users, messages). Omit or 0 = unbounded per field—see {@link CacheSizeLimits}. */
1624
1628
  cache?: CacheSizeLimits;
@@ -1918,6 +1922,11 @@ declare class Client extends EventEmitter {
1918
1922
  _pendingGuildIds: Set<string> | null;
1919
1923
  /** Timeout for guild stream when READY has no guilds (gateway sends only GUILD_CREATE). Cleared in finally. */
1920
1924
  private _guildStreamSettleTimeout;
1925
+ /**
1926
+ * When waitForGuilds delays Ready, gateway dispatches (except GUILD_CREATE) are queued and replayed after Ready.
1927
+ * Ensures user handlers that assume post-Ready setup (e.g. DB in Ready) do not run during the guild sync window.
1928
+ */
1929
+ private _deferredGatewayDispatches;
1921
1930
  /** Per-channel message cache (channelId -> messageId -> APIMessage). Used when options.cache.messages > 0. */
1922
1931
  private _messageCaches;
1923
1932
  /** @param options - Token, REST config, WebSocket, presence, etc. */
@@ -2016,11 +2025,18 @@ declare class Client extends EventEmitter {
2016
2025
  * @param payload - Gateway payload to send
2017
2026
  */
2018
2027
  sendToGateway(shardId: number, payload: GatewaySendPayload): void;
2028
+ /**
2029
+ * While {@link ClientOptions.waitForGuilds} delays Ready, defer user-facing dispatch handling until Ready fires.
2030
+ * GUILD_CREATE must still run immediately so guild cache and {@link Client._onGuildReceived} can finish the handshake.
2031
+ */
2032
+ private _shouldDeferGatewayDispatchUntilReady;
2019
2033
  /**
2020
2034
  * Run gateway event handlers. By default (see {@link ClientOptions.gatewayDeferHandlers}) work is deferred to the next
2021
2035
  * macrotask so user code does not block the WebSocket `message` callback.
2022
2036
  */
2023
2037
  private handleDispatch;
2038
+ private _dispatchGatewayPayload;
2039
+ private _flushDeferredGatewayDispatches;
2024
2040
  /**
2025
2041
  * Connect to the Fluxer gateway and authenticate.
2026
2042
  * @param token - Bot token (e.g. from FLUXER_BOT_TOKEN)
@@ -1618,7 +1618,11 @@ interface ClientOptions {
1618
1618
  intents?: number;
1619
1619
  /** Suppress the warning when intents are set (Fluxer does not support intents yet). */
1620
1620
  suppressIntentWarning?: boolean;
1621
- /** When true, delay the Ready event until all guilds from READY (including unavailable) have been received via GUILD_CREATE. Default: false. */
1621
+ /**
1622
+ * When true, delay the Ready event until all guilds from READY (including unavailable) have been received via GUILD_CREATE.
1623
+ * Other gateway dispatches (e.g. MESSAGE_CREATE) are queued and delivered after Ready so handlers can rely on post-Ready setup.
1624
+ * GUILD_CREATE still runs during sync so the guild cache can finish loading. Default: false.
1625
+ */
1622
1626
  waitForGuilds?: boolean;
1623
1627
  /** Cache size limits (channels, guilds, users, messages). Omit or 0 = unbounded per field—see {@link CacheSizeLimits}. */
1624
1628
  cache?: CacheSizeLimits;
@@ -1918,6 +1922,11 @@ declare class Client extends EventEmitter {
1918
1922
  _pendingGuildIds: Set<string> | null;
1919
1923
  /** Timeout for guild stream when READY has no guilds (gateway sends only GUILD_CREATE). Cleared in finally. */
1920
1924
  private _guildStreamSettleTimeout;
1925
+ /**
1926
+ * When waitForGuilds delays Ready, gateway dispatches (except GUILD_CREATE) are queued and replayed after Ready.
1927
+ * Ensures user handlers that assume post-Ready setup (e.g. DB in Ready) do not run during the guild sync window.
1928
+ */
1929
+ private _deferredGatewayDispatches;
1921
1930
  /** Per-channel message cache (channelId -> messageId -> APIMessage). Used when options.cache.messages > 0. */
1922
1931
  private _messageCaches;
1923
1932
  /** @param options - Token, REST config, WebSocket, presence, etc. */
@@ -2016,11 +2025,18 @@ declare class Client extends EventEmitter {
2016
2025
  * @param payload - Gateway payload to send
2017
2026
  */
2018
2027
  sendToGateway(shardId: number, payload: GatewaySendPayload): void;
2028
+ /**
2029
+ * While {@link ClientOptions.waitForGuilds} delays Ready, defer user-facing dispatch handling until Ready fires.
2030
+ * GUILD_CREATE must still run immediately so guild cache and {@link Client._onGuildReceived} can finish the handshake.
2031
+ */
2032
+ private _shouldDeferGatewayDispatchUntilReady;
2019
2033
  /**
2020
2034
  * Run gateway event handlers. By default (see {@link ClientOptions.gatewayDeferHandlers}) work is deferred to the next
2021
2035
  * macrotask so user code does not block the WebSocket `message` callback.
2022
2036
  */
2023
2037
  private handleDispatch;
2038
+ private _dispatchGatewayPayload;
2039
+ private _flushDeferredGatewayDispatches;
2024
2040
  /**
2025
2041
  * Connect to the Fluxer gateway and authenticate.
2026
2042
  * @param token - Bot token (e.g. from FLUXER_BOT_TOKEN)
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.3.0",
6
+ "version": "1.3.1",
7
7
  "description": "A fully-featured SDK for Fluxer bots",
8
8
  "repository": {
9
9
  "type": "git",
@@ -49,12 +49,12 @@
49
49
  "dist"
50
50
  ],
51
51
  "dependencies": {
52
- "@fluxerjs/rest": "1.3.0",
53
- "@fluxerjs/ws": "1.3.0",
54
- "@fluxerjs/builders": "1.3.0",
55
- "@fluxerjs/collection": "1.3.0",
56
- "@fluxerjs/types": "1.3.0",
57
- "@fluxerjs/util": "1.3.0"
52
+ "@fluxerjs/rest": "1.3.1",
53
+ "@fluxerjs/ws": "1.3.1",
54
+ "@fluxerjs/collection": "1.3.1",
55
+ "@fluxerjs/util": "1.3.1",
56
+ "@fluxerjs/types": "1.3.1",
57
+ "@fluxerjs/builders": "1.3.1"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/node": "^20.0.0",