@fluxerjs/core 2.0.0 → 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/client.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { C as CacheSizeLimits, r as Client, s as ClientEventMethods, t as ClientEvents, u as ClientOptions, H as Events } from './subpath-message-Acbzr5HA.mjs';
1
+ export { C as CacheSizeLimits, r as Client, s as ClientEventMethods, t as ClientEvents, u as ClientOptions, H as Events } from './subpath-message-CoDItxh0.mjs';
2
2
  import '@fluxerjs/collection';
3
3
  import '@fluxerjs/types';
4
4
  import 'events';
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { C as CacheSizeLimits, r as Client, s as ClientEventMethods, t as ClientEvents, u as ClientOptions, H as Events } from './subpath-message-Acbzr5HA.js';
1
+ export { C as CacheSizeLimits, r as Client, s as ClientEventMethods, t as ClientEvents, u as ClientOptions, H as Events } from './subpath-message-CoDItxh0.js';
2
2
  import '@fluxerjs/collection';
3
3
  import '@fluxerjs/types';
4
4
  import 'events';
package/dist/client.js CHANGED
@@ -485,6 +485,8 @@ var Events = {
485
485
  MessageReactionRemoveAll: "messageReactionRemoveAll",
486
486
  MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
487
487
  GuildCreate: "guildCreate",
488
+ GuildAvailable: "guildAvailable",
489
+ GuildUnavailable: "guildUnavailable",
488
490
  GuildUpdate: "guildUpdate",
489
491
  GuildDelete: "guildDelete",
490
492
  GuildBanAdd: "guildBanAdd",
@@ -3222,6 +3224,8 @@ var Guild = class extends Base {
3222
3224
  client;
3223
3225
  /** Snowflake ID of this guild. */
3224
3226
  id;
3227
+ /** Whether the guild is currently available through the gateway. */
3228
+ available = true;
3225
3229
  /** Guild name. */
3226
3230
  name;
3227
3231
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -3684,7 +3688,7 @@ var User = class extends Base {
3684
3688
  }
3685
3689
  /**
3686
3690
  * Send a DM to this user.
3687
- * @param options - Message content or {@link MessageSendOptions}
3691
+ * @param options - {@link MessagePrepareInput}
3688
3692
  * @returns Sent message
3689
3693
  */
3690
3694
  async send(options) {
@@ -4360,13 +4364,50 @@ function normalizeGuildPayload(raw) {
4360
4364
  }
4361
4365
 
4362
4366
  // src/client/eventHandlers/guilds.ts
4367
+ function markGuildUnavailable(client, id) {
4368
+ const guild = client.guilds.get(id);
4369
+ if (!guild || guild.available === false) return;
4370
+ guild.available = false;
4371
+ client.emit(Events.GuildUnavailable, guild);
4372
+ }
4373
+ function refreshRecoveredGuild(guild, data) {
4374
+ guild._patch(data);
4375
+ if (data.roles !== void 0) {
4376
+ guild.roles.clear();
4377
+ for (const role of data.roles) {
4378
+ guild.roles.set(role.id, new Role(guild.client, role, guild.id));
4379
+ }
4380
+ }
4381
+ if (data.channels !== void 0) {
4382
+ const recoveredChannelIds = new Set(data.channels.map((channel) => channel.id));
4383
+ for (const channel of guild.channels.values()) {
4384
+ guild.client.channels.delete(channel.id);
4385
+ if (!recoveredChannelIds.has(channel.id)) guild.client._clearMessageCache(channel.id);
4386
+ }
4387
+ guild.channels.clear();
4388
+ }
4389
+ }
4363
4390
  var guildHandlers = {
4364
4391
  GUILD_CREATE(client, d) {
4392
+ const raw = d;
4393
+ if (raw.unavailable === true) {
4394
+ if (typeof raw.id === "string") {
4395
+ try {
4396
+ markGuildUnavailable(client, raw.id);
4397
+ } finally {
4398
+ client._onGuildReceived(raw.id);
4399
+ }
4400
+ }
4401
+ return;
4402
+ }
4365
4403
  const guildData = normalizeGuildPayload(d);
4366
4404
  if (!guildData) return;
4367
- const guild = new Guild(client, guildData);
4368
- client.guilds.set(guild.id, guild);
4369
4405
  const g = d;
4406
+ const existing = client.guilds.get(guildData.id);
4407
+ const recovered = existing?.available === false;
4408
+ const guild = recovered && existing ? existing : new Guild(client, guildData);
4409
+ if (recovered) refreshRecoveredGuild(guild, g);
4410
+ client.guilds.set(guild.id, guild);
4370
4411
  for (const ch of g.channels ?? []) {
4371
4412
  const channel = Channel.from(client, ch);
4372
4413
  if (channel) {
@@ -4375,7 +4416,8 @@ var guildHandlers = {
4375
4416
  }
4376
4417
  }
4377
4418
  for (const m of g.members ?? []) cacheMember2(client, guild, m);
4378
- client.emit(Events.GuildCreate, guild);
4419
+ if (recovered) guild.available = true;
4420
+ client.emit(recovered ? Events.GuildAvailable : Events.GuildCreate, guild);
4379
4421
  if (g.voice_states?.length) {
4380
4422
  client.emit(Events.VoiceStatesSync, { guildId: guild.id, voiceStates: g.voice_states });
4381
4423
  }
@@ -4396,11 +4438,19 @@ var guildHandlers = {
4396
4438
  client.emit(Events.GuildUpdate, updated, updated);
4397
4439
  },
4398
4440
  GUILD_DELETE(client, d) {
4399
- const { id } = d;
4400
- const guild = client.guilds.get(id);
4401
- if (!guild) return;
4402
- client.guilds.delete(id);
4403
- client.emit(Events.GuildDelete, guild);
4441
+ const { id, unavailable } = d;
4442
+ try {
4443
+ if (unavailable === true) {
4444
+ markGuildUnavailable(client, id);
4445
+ return;
4446
+ }
4447
+ const guild = client.guilds.get(id);
4448
+ if (!guild) return;
4449
+ client.guilds.delete(id);
4450
+ client.emit(Events.GuildDelete, guild);
4451
+ } finally {
4452
+ client._onGuildReceived(id);
4453
+ }
4404
4454
  }
4405
4455
  };
4406
4456
 
@@ -4819,7 +4869,12 @@ function emitClientError(client, err) {
4819
4869
  function shouldDeferGatewayDispatchUntilReady(client, payload) {
4820
4870
  if (client.options.waitForGuilds !== true || client.readyAt !== null) return false;
4821
4871
  if (payload.op !== 0 || !payload.t) return false;
4822
- return payload.t !== "GUILD_CREATE";
4872
+ if (payload.t === "GUILD_CREATE") return false;
4873
+ if (payload.t === "GUILD_DELETE") {
4874
+ const data = payload.d;
4875
+ if (typeof data?.id === "string" && client._pendingGuildIds?.has(data.id)) return false;
4876
+ }
4877
+ return true;
4823
4878
  }
4824
4879
  function handleGatewayDispatch(client, payload, deferred) {
4825
4880
  if (payload.op !== 0 || !payload.t) return Promise.resolve();
package/dist/client.mjs CHANGED
@@ -461,6 +461,8 @@ var Events = {
461
461
  MessageReactionRemoveAll: "messageReactionRemoveAll",
462
462
  MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
463
463
  GuildCreate: "guildCreate",
464
+ GuildAvailable: "guildAvailable",
465
+ GuildUnavailable: "guildUnavailable",
464
466
  GuildUpdate: "guildUpdate",
465
467
  GuildDelete: "guildDelete",
466
468
  GuildBanAdd: "guildBanAdd",
@@ -3206,6 +3208,8 @@ var Guild = class extends Base {
3206
3208
  client;
3207
3209
  /** Snowflake ID of this guild. */
3208
3210
  id;
3211
+ /** Whether the guild is currently available through the gateway. */
3212
+ available = true;
3209
3213
  /** Guild name. */
3210
3214
  name;
3211
3215
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -3668,7 +3672,7 @@ var User = class extends Base {
3668
3672
  }
3669
3673
  /**
3670
3674
  * Send a DM to this user.
3671
- * @param options - Message content or {@link MessageSendOptions}
3675
+ * @param options - {@link MessagePrepareInput}
3672
3676
  * @returns Sent message
3673
3677
  */
3674
3678
  async send(options) {
@@ -4348,13 +4352,50 @@ function normalizeGuildPayload(raw) {
4348
4352
  }
4349
4353
 
4350
4354
  // src/client/eventHandlers/guilds.ts
4355
+ function markGuildUnavailable(client, id) {
4356
+ const guild = client.guilds.get(id);
4357
+ if (!guild || guild.available === false) return;
4358
+ guild.available = false;
4359
+ client.emit(Events.GuildUnavailable, guild);
4360
+ }
4361
+ function refreshRecoveredGuild(guild, data) {
4362
+ guild._patch(data);
4363
+ if (data.roles !== void 0) {
4364
+ guild.roles.clear();
4365
+ for (const role of data.roles) {
4366
+ guild.roles.set(role.id, new Role(guild.client, role, guild.id));
4367
+ }
4368
+ }
4369
+ if (data.channels !== void 0) {
4370
+ const recoveredChannelIds = new Set(data.channels.map((channel) => channel.id));
4371
+ for (const channel of guild.channels.values()) {
4372
+ guild.client.channels.delete(channel.id);
4373
+ if (!recoveredChannelIds.has(channel.id)) guild.client._clearMessageCache(channel.id);
4374
+ }
4375
+ guild.channels.clear();
4376
+ }
4377
+ }
4351
4378
  var guildHandlers = {
4352
4379
  GUILD_CREATE(client, d) {
4380
+ const raw = d;
4381
+ if (raw.unavailable === true) {
4382
+ if (typeof raw.id === "string") {
4383
+ try {
4384
+ markGuildUnavailable(client, raw.id);
4385
+ } finally {
4386
+ client._onGuildReceived(raw.id);
4387
+ }
4388
+ }
4389
+ return;
4390
+ }
4353
4391
  const guildData = normalizeGuildPayload(d);
4354
4392
  if (!guildData) return;
4355
- const guild = new Guild(client, guildData);
4356
- client.guilds.set(guild.id, guild);
4357
4393
  const g = d;
4394
+ const existing = client.guilds.get(guildData.id);
4395
+ const recovered = existing?.available === false;
4396
+ const guild = recovered && existing ? existing : new Guild(client, guildData);
4397
+ if (recovered) refreshRecoveredGuild(guild, g);
4398
+ client.guilds.set(guild.id, guild);
4358
4399
  for (const ch of g.channels ?? []) {
4359
4400
  const channel = Channel.from(client, ch);
4360
4401
  if (channel) {
@@ -4363,7 +4404,8 @@ var guildHandlers = {
4363
4404
  }
4364
4405
  }
4365
4406
  for (const m of g.members ?? []) cacheMember2(client, guild, m);
4366
- client.emit(Events.GuildCreate, guild);
4407
+ if (recovered) guild.available = true;
4408
+ client.emit(recovered ? Events.GuildAvailable : Events.GuildCreate, guild);
4367
4409
  if (g.voice_states?.length) {
4368
4410
  client.emit(Events.VoiceStatesSync, { guildId: guild.id, voiceStates: g.voice_states });
4369
4411
  }
@@ -4384,11 +4426,19 @@ var guildHandlers = {
4384
4426
  client.emit(Events.GuildUpdate, updated, updated);
4385
4427
  },
4386
4428
  GUILD_DELETE(client, d) {
4387
- const { id } = d;
4388
- const guild = client.guilds.get(id);
4389
- if (!guild) return;
4390
- client.guilds.delete(id);
4391
- client.emit(Events.GuildDelete, guild);
4429
+ const { id, unavailable } = d;
4430
+ try {
4431
+ if (unavailable === true) {
4432
+ markGuildUnavailable(client, id);
4433
+ return;
4434
+ }
4435
+ const guild = client.guilds.get(id);
4436
+ if (!guild) return;
4437
+ client.guilds.delete(id);
4438
+ client.emit(Events.GuildDelete, guild);
4439
+ } finally {
4440
+ client._onGuildReceived(id);
4441
+ }
4392
4442
  }
4393
4443
  };
4394
4444
 
@@ -4810,7 +4860,12 @@ function emitClientError(client, err) {
4810
4860
  function shouldDeferGatewayDispatchUntilReady(client, payload) {
4811
4861
  if (client.options.waitForGuilds !== true || client.readyAt !== null) return false;
4812
4862
  if (payload.op !== 0 || !payload.t) return false;
4813
- return payload.t !== "GUILD_CREATE";
4863
+ if (payload.t === "GUILD_CREATE") return false;
4864
+ if (payload.t === "GUILD_DELETE") {
4865
+ const data = payload.d;
4866
+ if (typeof data?.id === "string" && client._pendingGuildIds?.has(data.id)) return false;
4867
+ }
4868
+ return true;
4814
4869
  }
4815
4870
  function handleGatewayDispatch(client, payload, deferred) {
4816
4871
  if (payload.op !== 0 || !payload.t) return Promise.resolve();
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'events';
2
- import { F as DiscoveryOrigin, u as ClientOptions, r as Client } from './subpath-message-Acbzr5HA.mjs';
2
+ import { F as DiscoveryOrigin, u as ClientOptions, r as Client } from './subpath-message-CoDItxh0.mjs';
3
3
  import '@fluxerjs/collection';
4
4
  import '@fluxerjs/types';
5
5
  import '@fluxerjs/rest';
package/dist/cluster.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'events';
2
- import { F as DiscoveryOrigin, u as ClientOptions, r as Client } from './subpath-message-Acbzr5HA.js';
2
+ import { F as DiscoveryOrigin, u as ClientOptions, r as Client } from './subpath-message-CoDItxh0.js';
3
3
  import '@fluxerjs/collection';
4
4
  import '@fluxerjs/types';
5
5
  import '@fluxerjs/rest';
package/dist/cluster.js CHANGED
@@ -49,6 +49,8 @@ var Events = {
49
49
  MessageReactionRemoveAll: "messageReactionRemoveAll",
50
50
  MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
51
51
  GuildCreate: "guildCreate",
52
+ GuildAvailable: "guildAvailable",
53
+ GuildUnavailable: "guildUnavailable",
52
54
  GuildUpdate: "guildUpdate",
53
55
  GuildDelete: "guildDelete",
54
56
  GuildBanAdd: "guildBanAdd",
@@ -3225,6 +3227,8 @@ var Guild = class extends Base {
3225
3227
  client;
3226
3228
  /** Snowflake ID of this guild. */
3227
3229
  id;
3230
+ /** Whether the guild is currently available through the gateway. */
3231
+ available = true;
3228
3232
  /** Guild name. */
3229
3233
  name;
3230
3234
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -3687,7 +3691,7 @@ var User = class extends Base {
3687
3691
  }
3688
3692
  /**
3689
3693
  * Send a DM to this user.
3690
- * @param options - Message content or {@link MessageSendOptions}
3694
+ * @param options - {@link MessagePrepareInput}
3691
3695
  * @returns Sent message
3692
3696
  */
3693
3697
  async send(options) {
@@ -4363,13 +4367,50 @@ function normalizeGuildPayload(raw) {
4363
4367
  }
4364
4368
 
4365
4369
  // src/client/eventHandlers/guilds.ts
4370
+ function markGuildUnavailable(client, id) {
4371
+ const guild = client.guilds.get(id);
4372
+ if (!guild || guild.available === false) return;
4373
+ guild.available = false;
4374
+ client.emit(Events.GuildUnavailable, guild);
4375
+ }
4376
+ function refreshRecoveredGuild(guild, data) {
4377
+ guild._patch(data);
4378
+ if (data.roles !== void 0) {
4379
+ guild.roles.clear();
4380
+ for (const role of data.roles) {
4381
+ guild.roles.set(role.id, new Role(guild.client, role, guild.id));
4382
+ }
4383
+ }
4384
+ if (data.channels !== void 0) {
4385
+ const recoveredChannelIds = new Set(data.channels.map((channel) => channel.id));
4386
+ for (const channel of guild.channels.values()) {
4387
+ guild.client.channels.delete(channel.id);
4388
+ if (!recoveredChannelIds.has(channel.id)) guild.client._clearMessageCache(channel.id);
4389
+ }
4390
+ guild.channels.clear();
4391
+ }
4392
+ }
4366
4393
  var guildHandlers = {
4367
4394
  GUILD_CREATE(client, d) {
4395
+ const raw = d;
4396
+ if (raw.unavailable === true) {
4397
+ if (typeof raw.id === "string") {
4398
+ try {
4399
+ markGuildUnavailable(client, raw.id);
4400
+ } finally {
4401
+ client._onGuildReceived(raw.id);
4402
+ }
4403
+ }
4404
+ return;
4405
+ }
4368
4406
  const guildData = normalizeGuildPayload(d);
4369
4407
  if (!guildData) return;
4370
- const guild = new Guild(client, guildData);
4371
- client.guilds.set(guild.id, guild);
4372
4408
  const g = d;
4409
+ const existing = client.guilds.get(guildData.id);
4410
+ const recovered = existing?.available === false;
4411
+ const guild = recovered && existing ? existing : new Guild(client, guildData);
4412
+ if (recovered) refreshRecoveredGuild(guild, g);
4413
+ client.guilds.set(guild.id, guild);
4373
4414
  for (const ch of g.channels ?? []) {
4374
4415
  const channel = Channel.from(client, ch);
4375
4416
  if (channel) {
@@ -4378,7 +4419,8 @@ var guildHandlers = {
4378
4419
  }
4379
4420
  }
4380
4421
  for (const m of g.members ?? []) cacheMember2(client, guild, m);
4381
- client.emit(Events.GuildCreate, guild);
4422
+ if (recovered) guild.available = true;
4423
+ client.emit(recovered ? Events.GuildAvailable : Events.GuildCreate, guild);
4382
4424
  if (g.voice_states?.length) {
4383
4425
  client.emit(Events.VoiceStatesSync, { guildId: guild.id, voiceStates: g.voice_states });
4384
4426
  }
@@ -4399,11 +4441,19 @@ var guildHandlers = {
4399
4441
  client.emit(Events.GuildUpdate, updated, updated);
4400
4442
  },
4401
4443
  GUILD_DELETE(client, d) {
4402
- const { id } = d;
4403
- const guild = client.guilds.get(id);
4404
- if (!guild) return;
4405
- client.guilds.delete(id);
4406
- client.emit(Events.GuildDelete, guild);
4444
+ const { id, unavailable } = d;
4445
+ try {
4446
+ if (unavailable === true) {
4447
+ markGuildUnavailable(client, id);
4448
+ return;
4449
+ }
4450
+ const guild = client.guilds.get(id);
4451
+ if (!guild) return;
4452
+ client.guilds.delete(id);
4453
+ client.emit(Events.GuildDelete, guild);
4454
+ } finally {
4455
+ client._onGuildReceived(id);
4456
+ }
4407
4457
  }
4408
4458
  };
4409
4459
 
@@ -4822,7 +4872,12 @@ function emitClientError(client, err) {
4822
4872
  function shouldDeferGatewayDispatchUntilReady(client, payload) {
4823
4873
  if (client.options.waitForGuilds !== true || client.readyAt !== null) return false;
4824
4874
  if (payload.op !== 0 || !payload.t) return false;
4825
- return payload.t !== "GUILD_CREATE";
4875
+ if (payload.t === "GUILD_CREATE") return false;
4876
+ if (payload.t === "GUILD_DELETE") {
4877
+ const data = payload.d;
4878
+ if (typeof data?.id === "string" && client._pendingGuildIds?.has(data.id)) return false;
4879
+ }
4880
+ return true;
4826
4881
  }
4827
4882
  function handleGatewayDispatch(client, payload, deferred) {
4828
4883
  if (payload.op !== 0 || !payload.t) return Promise.resolve();
package/dist/cluster.mjs CHANGED
@@ -20,6 +20,8 @@ var Events = {
20
20
  MessageReactionRemoveAll: "messageReactionRemoveAll",
21
21
  MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
22
22
  GuildCreate: "guildCreate",
23
+ GuildAvailable: "guildAvailable",
24
+ GuildUnavailable: "guildUnavailable",
23
25
  GuildUpdate: "guildUpdate",
24
26
  GuildDelete: "guildDelete",
25
27
  GuildBanAdd: "guildBanAdd",
@@ -3207,6 +3209,8 @@ var Guild = class extends Base {
3207
3209
  client;
3208
3210
  /** Snowflake ID of this guild. */
3209
3211
  id;
3212
+ /** Whether the guild is currently available through the gateway. */
3213
+ available = true;
3210
3214
  /** Guild name. */
3211
3215
  name;
3212
3216
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -3669,7 +3673,7 @@ var User = class extends Base {
3669
3673
  }
3670
3674
  /**
3671
3675
  * Send a DM to this user.
3672
- * @param options - Message content or {@link MessageSendOptions}
3676
+ * @param options - {@link MessagePrepareInput}
3673
3677
  * @returns Sent message
3674
3678
  */
3675
3679
  async send(options) {
@@ -4349,13 +4353,50 @@ function normalizeGuildPayload(raw) {
4349
4353
  }
4350
4354
 
4351
4355
  // src/client/eventHandlers/guilds.ts
4356
+ function markGuildUnavailable(client, id) {
4357
+ const guild = client.guilds.get(id);
4358
+ if (!guild || guild.available === false) return;
4359
+ guild.available = false;
4360
+ client.emit(Events.GuildUnavailable, guild);
4361
+ }
4362
+ function refreshRecoveredGuild(guild, data) {
4363
+ guild._patch(data);
4364
+ if (data.roles !== void 0) {
4365
+ guild.roles.clear();
4366
+ for (const role of data.roles) {
4367
+ guild.roles.set(role.id, new Role(guild.client, role, guild.id));
4368
+ }
4369
+ }
4370
+ if (data.channels !== void 0) {
4371
+ const recoveredChannelIds = new Set(data.channels.map((channel) => channel.id));
4372
+ for (const channel of guild.channels.values()) {
4373
+ guild.client.channels.delete(channel.id);
4374
+ if (!recoveredChannelIds.has(channel.id)) guild.client._clearMessageCache(channel.id);
4375
+ }
4376
+ guild.channels.clear();
4377
+ }
4378
+ }
4352
4379
  var guildHandlers = {
4353
4380
  GUILD_CREATE(client, d) {
4381
+ const raw = d;
4382
+ if (raw.unavailable === true) {
4383
+ if (typeof raw.id === "string") {
4384
+ try {
4385
+ markGuildUnavailable(client, raw.id);
4386
+ } finally {
4387
+ client._onGuildReceived(raw.id);
4388
+ }
4389
+ }
4390
+ return;
4391
+ }
4354
4392
  const guildData = normalizeGuildPayload(d);
4355
4393
  if (!guildData) return;
4356
- const guild = new Guild(client, guildData);
4357
- client.guilds.set(guild.id, guild);
4358
4394
  const g = d;
4395
+ const existing = client.guilds.get(guildData.id);
4396
+ const recovered = existing?.available === false;
4397
+ const guild = recovered && existing ? existing : new Guild(client, guildData);
4398
+ if (recovered) refreshRecoveredGuild(guild, g);
4399
+ client.guilds.set(guild.id, guild);
4359
4400
  for (const ch of g.channels ?? []) {
4360
4401
  const channel = Channel.from(client, ch);
4361
4402
  if (channel) {
@@ -4364,7 +4405,8 @@ var guildHandlers = {
4364
4405
  }
4365
4406
  }
4366
4407
  for (const m of g.members ?? []) cacheMember2(client, guild, m);
4367
- client.emit(Events.GuildCreate, guild);
4408
+ if (recovered) guild.available = true;
4409
+ client.emit(recovered ? Events.GuildAvailable : Events.GuildCreate, guild);
4368
4410
  if (g.voice_states?.length) {
4369
4411
  client.emit(Events.VoiceStatesSync, { guildId: guild.id, voiceStates: g.voice_states });
4370
4412
  }
@@ -4385,11 +4427,19 @@ var guildHandlers = {
4385
4427
  client.emit(Events.GuildUpdate, updated, updated);
4386
4428
  },
4387
4429
  GUILD_DELETE(client, d) {
4388
- const { id } = d;
4389
- const guild = client.guilds.get(id);
4390
- if (!guild) return;
4391
- client.guilds.delete(id);
4392
- client.emit(Events.GuildDelete, guild);
4430
+ const { id, unavailable } = d;
4431
+ try {
4432
+ if (unavailable === true) {
4433
+ markGuildUnavailable(client, id);
4434
+ return;
4435
+ }
4436
+ const guild = client.guilds.get(id);
4437
+ if (!guild) return;
4438
+ client.guilds.delete(id);
4439
+ client.emit(Events.GuildDelete, guild);
4440
+ } finally {
4441
+ client._onGuildReceived(id);
4442
+ }
4393
4443
  }
4394
4444
  };
4395
4445
 
@@ -4811,7 +4861,12 @@ function emitClientError(client, err) {
4811
4861
  function shouldDeferGatewayDispatchUntilReady(client, payload) {
4812
4862
  if (client.options.waitForGuilds !== true || client.readyAt !== null) return false;
4813
4863
  if (payload.op !== 0 || !payload.t) return false;
4814
- return payload.t !== "GUILD_CREATE";
4864
+ if (payload.t === "GUILD_CREATE") return false;
4865
+ if (payload.t === "GUILD_DELETE") {
4866
+ const data = payload.d;
4867
+ if (typeof data?.id === "string" && client._pendingGuildIds?.has(data.id)) return false;
4868
+ }
4869
+ return true;
4815
4870
  }
4816
4871
  function handleGatewayDispatch(client, payload, deferred) {
4817
4872
  if (payload.op !== 0 || !payload.t) return Promise.resolve();
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AllowedMentions, a as AllowedMentionsOptions, b as AttachmentUploadCompleteItem, c as AttachmentUploadCompleteResponse, d as AttachmentUploadPlanItem, e as AttachmentUploadPlanResponse, f as AuditLogEntryPayload, g as AuditLogFetchPayload, B as Base, h as BulkFetchMessagesChannelResult, i as BulkFetchMessagesOptions, j as BulkFetchMessagesRequest, k as BulkFetchMessagesResult, C as CacheSizeLimits, l as CategoryChannel, m as Channel, n as ChannelEditOptions, o as ChannelInviteCreateOptions, p as ChannelManager, q as ChannelSlowmodePayload, r as Client, s as ClientEventMethods, t as ClientEvents, u as ClientOptions, v as ClientUser, w as CollectedReaction, D as DEFAULT_CACHE_LIMITS, x as DEFAULT_INSTANCE_ENDPOINTS, y as DMChannel, z as DiscoveryApplicationOptions, E as DiscoveryApplicationPayload, F as DiscoveryOrigin, G as DiscoveryStatusPayload, H as Events, I as ExpressionCreateOptions, J as ExpressionEditOptions, K as FetchMessagesOptions, L as FetchPinnedMessagesOptions, M as FetchedUserWithProfile, N as Guild, O as GuildBan, P as GuildChannel, Q as GuildEmoji, R as GuildEmojisUpdatePayload, S as GuildMember, T as GuildMemberEditOptions, U as GuildMemberManager, V as GuildMemberRoleManager, W as GuildMemberSearchHit, X as GuildMemberSearchOptions, Y as GuildMemberSearchPayload, Z as GuildRoleDeletePayload, _ as GuildSticker, $ as Invite, a0 as InviteDeletePayload, a1 as LinkChannel, a2 as Message, a3 as MessageAttachmentEdit, a4 as MessageCollector, a5 as MessageCollectorEndReason, a6 as MessageCollectorOptions, a7 as MessageDeleteBulkPayload, a8 as MessageEditOptions, a9 as MessageManager, aa as MessageReaction, ab as MessageReactionPayload, ac as MessageReactionRemoveAllPayload, ad as MessageReactionRemoveEmojiPayload, ae as MessageReplyTarget, af as MessageSendOptions, ag as PackBulkCreatePayload, ah as PackCreateOptions, ai as PackDashboardPayload, aj as PackDashboardSectionPayload, ak as PackEditOptions, al as PackEmojiPayload, am as PackInviteCreateOptions, an as PackInvitePayload, ao as PackManager, ap as PackStickerPayload, aq as PackSummaryPayload, ar as PartialMessage, as as PartialUserGuildPayload, at as PinnedMessagesPage, au as PresenceUpdateOptions, av as PresenceUpdatePayload, aw as ProfilePayload, ax as ReactionCollector, ay as ReactionCollectorEndReason, az as ReactionCollectorOptions, aA as ReactionEmojiPayload, aB as ReplyOptions, aC as ResolvedInstance, aD as Role, aE as RoleCreateOptions, aF as RoleEditOptions, aG as RoleResolvable, aH as RtcRegionPayload, aI as StickerCreateOptions, aJ as StickerEditOptions, aK as SudoVerificationOptions, aL as TextChannel, aM as TypingStartPayload, aN as UploadFileForSend, aO as User, aP as UserManager, aQ as VanityURLPayload, aR as VoiceChannel, aS as Webhook, aT as WebhookEditOptions, aU as WebhookMessageEditOptions, aV as WebhookSendOptions, aW as inviteUrl, aX as normalizeApiOrigin, aY as parseInstanceDiscovery, aZ as resolveInstanceEndpoints, a_ as toAttachmentUploadCompleteBody, a$ as toAttachmentUploadPlanBody, b0 as toBulkFetchWire, b1 as toChannelEditBody, b2 as toChannelInviteBody, b3 as toDiscoveryApplicationPayload, b4 as toDiscoveryBody, b5 as toDiscoveryStatusPayload, b6 as toEmojiCreateBody, b7 as toEmojiEditBody, b8 as toMemberEditBody, b9 as toMemberSearchBody, ba as toMessageAttachmentEditWire, bb as toPackInviteBody, bc as toPackSummaryPayload, bd as toPresenceWire, be as toProfilePayload, bf as toStickerCreateBody, bg as toStickerEditBody, bh as toSudoBody } from './subpath-message-Acbzr5HA.mjs';
1
+ export { A as AllowedMentions, a as AllowedMentionsOptions, b as AttachmentUploadCompleteItem, c as AttachmentUploadCompleteResponse, d as AttachmentUploadPlanItem, e as AttachmentUploadPlanResponse, f as AuditLogEntryPayload, g as AuditLogFetchPayload, B as Base, h as BulkFetchMessagesChannelResult, i as BulkFetchMessagesOptions, j as BulkFetchMessagesRequest, k as BulkFetchMessagesResult, C as CacheSizeLimits, l as CategoryChannel, m as Channel, n as ChannelEditOptions, o as ChannelInviteCreateOptions, p as ChannelManager, q as ChannelSlowmodePayload, r as Client, s as ClientEventMethods, t as ClientEvents, u as ClientOptions, v as ClientUser, w as CollectedReaction, D as DEFAULT_CACHE_LIMITS, x as DEFAULT_INSTANCE_ENDPOINTS, y as DMChannel, z as DiscoveryApplicationOptions, E as DiscoveryApplicationPayload, F as DiscoveryOrigin, G as DiscoveryStatusPayload, H as Events, I as ExpressionCreateOptions, J as ExpressionEditOptions, K as FetchMessagesOptions, L as FetchPinnedMessagesOptions, M as FetchedUserWithProfile, N as Guild, O as GuildBan, P as GuildChannel, Q as GuildEmoji, R as GuildEmojisUpdatePayload, S as GuildMember, T as GuildMemberEditOptions, U as GuildMemberManager, V as GuildMemberRoleManager, W as GuildMemberSearchHit, X as GuildMemberSearchOptions, Y as GuildMemberSearchPayload, Z as GuildRoleDeletePayload, _ as GuildSticker, $ as Invite, a0 as InviteDeletePayload, a1 as LinkChannel, a2 as Message, a3 as MessageAttachmentEdit, a4 as MessageCollector, a5 as MessageCollectorEndReason, a6 as MessageCollectorOptions, a7 as MessageDeleteBulkPayload, a8 as MessageEditOptions, a9 as MessageManager, aa as MessageReaction, ab as MessageReactionPayload, ac as MessageReactionRemoveAllPayload, ad as MessageReactionRemoveEmojiPayload, ae as MessageReplyTarget, af as MessageSendOptions, ag as PackBulkCreatePayload, ah as PackCreateOptions, ai as PackDashboardPayload, aj as PackDashboardSectionPayload, ak as PackEditOptions, al as PackEmojiPayload, am as PackInviteCreateOptions, an as PackInvitePayload, ao as PackManager, ap as PackStickerPayload, aq as PackSummaryPayload, ar as PartialMessage, as as PartialUserGuildPayload, at as PinnedMessagesPage, au as PresenceUpdateOptions, av as PresenceUpdatePayload, aw as ProfilePayload, ax as ReactionCollector, ay as ReactionCollectorEndReason, az as ReactionCollectorOptions, aA as ReactionEmojiPayload, aB as ReplyOptions, aC as ResolvedInstance, aD as Role, aE as RoleCreateOptions, aF as RoleEditOptions, aG as RoleResolvable, aH as RtcRegionPayload, aI as StickerCreateOptions, aJ as StickerEditOptions, aK as SudoVerificationOptions, aL as TextChannel, aM as TypingStartPayload, aN as UploadFileForSend, aO as User, aP as UserManager, aQ as VanityURLPayload, aR as VoiceChannel, aS as Webhook, aT as WebhookEditOptions, aU as WebhookMessageEditOptions, aV as WebhookSendOptions, aW as inviteUrl, aX as normalizeApiOrigin, aY as parseInstanceDiscovery, aZ as resolveInstanceEndpoints, a_ as toAttachmentUploadCompleteBody, a$ as toAttachmentUploadPlanBody, b0 as toBulkFetchWire, b1 as toChannelEditBody, b2 as toChannelInviteBody, b3 as toDiscoveryApplicationPayload, b4 as toDiscoveryBody, b5 as toDiscoveryStatusPayload, b6 as toEmojiCreateBody, b7 as toEmojiEditBody, b8 as toMemberEditBody, b9 as toMemberSearchBody, ba as toMessageAttachmentEditWire, bb as toPackInviteBody, bc as toPackSummaryPayload, bd as toPresenceWire, be as toProfilePayload, bf as toStickerCreateBody, bg as toStickerEditBody, bh as toSudoBody } from './subpath-message-CoDItxh0.mjs';
2
2
  export { APIAllowedMentions, APIBulkMessageFetchRequest, APIBulkMessageFetchResponse, APIBulkMessageFetchResponseChannel, APIGuildMemberSearchResponse, APIInstance, APIInstanceEndpoints, APIWellKnownFluxer, AllowedMentionType, AuditLogActionType, ChannelType, ContentWarningLevel, GatewayOpcodes, GuildMemberProfileFlags, GuildNSFWLevel, GuildOperations, InviteType, MessageAttachmentFlags, MessageFlags, MessageReferenceType, MessageType, OverwriteType, PublicUserFlags, RelationshipType, Routes, SplashCardAlignment, SystemChannelFlags } from '@fluxerjs/types';
3
3
  export { AttachmentBuilder, EmbedBuilder, MessagePayload } from '@fluxerjs/builders';
4
4
  export { ErrorCodes, FluxerError, FluxerErrorOptions, MessageFlagsBitField, MessageFlagsBits, MessageFlagsResolvable, MessageFlagsString, PermissionFlags, PermissionResolvable, PermissionString, PermissionsBitField, UserFlagsBitField, UserFlagsBits, UserFlagsResolvable, UserFlagsString, parsePrefixCommand, parseUserMention, resolvePermissionsToBitfield, resolveTenorToImageUrl } from '@fluxerjs/util';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AllowedMentions, a as AllowedMentionsOptions, b as AttachmentUploadCompleteItem, c as AttachmentUploadCompleteResponse, d as AttachmentUploadPlanItem, e as AttachmentUploadPlanResponse, f as AuditLogEntryPayload, g as AuditLogFetchPayload, B as Base, h as BulkFetchMessagesChannelResult, i as BulkFetchMessagesOptions, j as BulkFetchMessagesRequest, k as BulkFetchMessagesResult, C as CacheSizeLimits, l as CategoryChannel, m as Channel, n as ChannelEditOptions, o as ChannelInviteCreateOptions, p as ChannelManager, q as ChannelSlowmodePayload, r as Client, s as ClientEventMethods, t as ClientEvents, u as ClientOptions, v as ClientUser, w as CollectedReaction, D as DEFAULT_CACHE_LIMITS, x as DEFAULT_INSTANCE_ENDPOINTS, y as DMChannel, z as DiscoveryApplicationOptions, E as DiscoveryApplicationPayload, F as DiscoveryOrigin, G as DiscoveryStatusPayload, H as Events, I as ExpressionCreateOptions, J as ExpressionEditOptions, K as FetchMessagesOptions, L as FetchPinnedMessagesOptions, M as FetchedUserWithProfile, N as Guild, O as GuildBan, P as GuildChannel, Q as GuildEmoji, R as GuildEmojisUpdatePayload, S as GuildMember, T as GuildMemberEditOptions, U as GuildMemberManager, V as GuildMemberRoleManager, W as GuildMemberSearchHit, X as GuildMemberSearchOptions, Y as GuildMemberSearchPayload, Z as GuildRoleDeletePayload, _ as GuildSticker, $ as Invite, a0 as InviteDeletePayload, a1 as LinkChannel, a2 as Message, a3 as MessageAttachmentEdit, a4 as MessageCollector, a5 as MessageCollectorEndReason, a6 as MessageCollectorOptions, a7 as MessageDeleteBulkPayload, a8 as MessageEditOptions, a9 as MessageManager, aa as MessageReaction, ab as MessageReactionPayload, ac as MessageReactionRemoveAllPayload, ad as MessageReactionRemoveEmojiPayload, ae as MessageReplyTarget, af as MessageSendOptions, ag as PackBulkCreatePayload, ah as PackCreateOptions, ai as PackDashboardPayload, aj as PackDashboardSectionPayload, ak as PackEditOptions, al as PackEmojiPayload, am as PackInviteCreateOptions, an as PackInvitePayload, ao as PackManager, ap as PackStickerPayload, aq as PackSummaryPayload, ar as PartialMessage, as as PartialUserGuildPayload, at as PinnedMessagesPage, au as PresenceUpdateOptions, av as PresenceUpdatePayload, aw as ProfilePayload, ax as ReactionCollector, ay as ReactionCollectorEndReason, az as ReactionCollectorOptions, aA as ReactionEmojiPayload, aB as ReplyOptions, aC as ResolvedInstance, aD as Role, aE as RoleCreateOptions, aF as RoleEditOptions, aG as RoleResolvable, aH as RtcRegionPayload, aI as StickerCreateOptions, aJ as StickerEditOptions, aK as SudoVerificationOptions, aL as TextChannel, aM as TypingStartPayload, aN as UploadFileForSend, aO as User, aP as UserManager, aQ as VanityURLPayload, aR as VoiceChannel, aS as Webhook, aT as WebhookEditOptions, aU as WebhookMessageEditOptions, aV as WebhookSendOptions, aW as inviteUrl, aX as normalizeApiOrigin, aY as parseInstanceDiscovery, aZ as resolveInstanceEndpoints, a_ as toAttachmentUploadCompleteBody, a$ as toAttachmentUploadPlanBody, b0 as toBulkFetchWire, b1 as toChannelEditBody, b2 as toChannelInviteBody, b3 as toDiscoveryApplicationPayload, b4 as toDiscoveryBody, b5 as toDiscoveryStatusPayload, b6 as toEmojiCreateBody, b7 as toEmojiEditBody, b8 as toMemberEditBody, b9 as toMemberSearchBody, ba as toMessageAttachmentEditWire, bb as toPackInviteBody, bc as toPackSummaryPayload, bd as toPresenceWire, be as toProfilePayload, bf as toStickerCreateBody, bg as toStickerEditBody, bh as toSudoBody } from './subpath-message-Acbzr5HA.js';
1
+ export { A as AllowedMentions, a as AllowedMentionsOptions, b as AttachmentUploadCompleteItem, c as AttachmentUploadCompleteResponse, d as AttachmentUploadPlanItem, e as AttachmentUploadPlanResponse, f as AuditLogEntryPayload, g as AuditLogFetchPayload, B as Base, h as BulkFetchMessagesChannelResult, i as BulkFetchMessagesOptions, j as BulkFetchMessagesRequest, k as BulkFetchMessagesResult, C as CacheSizeLimits, l as CategoryChannel, m as Channel, n as ChannelEditOptions, o as ChannelInviteCreateOptions, p as ChannelManager, q as ChannelSlowmodePayload, r as Client, s as ClientEventMethods, t as ClientEvents, u as ClientOptions, v as ClientUser, w as CollectedReaction, D as DEFAULT_CACHE_LIMITS, x as DEFAULT_INSTANCE_ENDPOINTS, y as DMChannel, z as DiscoveryApplicationOptions, E as DiscoveryApplicationPayload, F as DiscoveryOrigin, G as DiscoveryStatusPayload, H as Events, I as ExpressionCreateOptions, J as ExpressionEditOptions, K as FetchMessagesOptions, L as FetchPinnedMessagesOptions, M as FetchedUserWithProfile, N as Guild, O as GuildBan, P as GuildChannel, Q as GuildEmoji, R as GuildEmojisUpdatePayload, S as GuildMember, T as GuildMemberEditOptions, U as GuildMemberManager, V as GuildMemberRoleManager, W as GuildMemberSearchHit, X as GuildMemberSearchOptions, Y as GuildMemberSearchPayload, Z as GuildRoleDeletePayload, _ as GuildSticker, $ as Invite, a0 as InviteDeletePayload, a1 as LinkChannel, a2 as Message, a3 as MessageAttachmentEdit, a4 as MessageCollector, a5 as MessageCollectorEndReason, a6 as MessageCollectorOptions, a7 as MessageDeleteBulkPayload, a8 as MessageEditOptions, a9 as MessageManager, aa as MessageReaction, ab as MessageReactionPayload, ac as MessageReactionRemoveAllPayload, ad as MessageReactionRemoveEmojiPayload, ae as MessageReplyTarget, af as MessageSendOptions, ag as PackBulkCreatePayload, ah as PackCreateOptions, ai as PackDashboardPayload, aj as PackDashboardSectionPayload, ak as PackEditOptions, al as PackEmojiPayload, am as PackInviteCreateOptions, an as PackInvitePayload, ao as PackManager, ap as PackStickerPayload, aq as PackSummaryPayload, ar as PartialMessage, as as PartialUserGuildPayload, at as PinnedMessagesPage, au as PresenceUpdateOptions, av as PresenceUpdatePayload, aw as ProfilePayload, ax as ReactionCollector, ay as ReactionCollectorEndReason, az as ReactionCollectorOptions, aA as ReactionEmojiPayload, aB as ReplyOptions, aC as ResolvedInstance, aD as Role, aE as RoleCreateOptions, aF as RoleEditOptions, aG as RoleResolvable, aH as RtcRegionPayload, aI as StickerCreateOptions, aJ as StickerEditOptions, aK as SudoVerificationOptions, aL as TextChannel, aM as TypingStartPayload, aN as UploadFileForSend, aO as User, aP as UserManager, aQ as VanityURLPayload, aR as VoiceChannel, aS as Webhook, aT as WebhookEditOptions, aU as WebhookMessageEditOptions, aV as WebhookSendOptions, aW as inviteUrl, aX as normalizeApiOrigin, aY as parseInstanceDiscovery, aZ as resolveInstanceEndpoints, a_ as toAttachmentUploadCompleteBody, a$ as toAttachmentUploadPlanBody, b0 as toBulkFetchWire, b1 as toChannelEditBody, b2 as toChannelInviteBody, b3 as toDiscoveryApplicationPayload, b4 as toDiscoveryBody, b5 as toDiscoveryStatusPayload, b6 as toEmojiCreateBody, b7 as toEmojiEditBody, b8 as toMemberEditBody, b9 as toMemberSearchBody, ba as toMessageAttachmentEditWire, bb as toPackInviteBody, bc as toPackSummaryPayload, bd as toPresenceWire, be as toProfilePayload, bf as toStickerCreateBody, bg as toStickerEditBody, bh as toSudoBody } from './subpath-message-CoDItxh0.js';
2
2
  export { APIAllowedMentions, APIBulkMessageFetchRequest, APIBulkMessageFetchResponse, APIBulkMessageFetchResponseChannel, APIGuildMemberSearchResponse, APIInstance, APIInstanceEndpoints, APIWellKnownFluxer, AllowedMentionType, AuditLogActionType, ChannelType, ContentWarningLevel, GatewayOpcodes, GuildMemberProfileFlags, GuildNSFWLevel, GuildOperations, InviteType, MessageAttachmentFlags, MessageFlags, MessageReferenceType, MessageType, OverwriteType, PublicUserFlags, RelationshipType, Routes, SplashCardAlignment, SystemChannelFlags } from '@fluxerjs/types';
3
3
  export { AttachmentBuilder, EmbedBuilder, MessagePayload } from '@fluxerjs/builders';
4
4
  export { ErrorCodes, FluxerError, FluxerErrorOptions, MessageFlagsBitField, MessageFlagsBits, MessageFlagsResolvable, MessageFlagsString, PermissionFlags, PermissionResolvable, PermissionString, PermissionsBitField, UserFlagsBitField, UserFlagsBits, UserFlagsResolvable, UserFlagsString, parsePrefixCommand, parseUserMention, resolvePermissionsToBitfield, resolveTenorToImageUrl } from '@fluxerjs/util';
package/dist/index.js CHANGED
@@ -594,6 +594,8 @@ var Events = {
594
594
  MessageReactionRemoveAll: "messageReactionRemoveAll",
595
595
  MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
596
596
  GuildCreate: "guildCreate",
597
+ GuildAvailable: "guildAvailable",
598
+ GuildUnavailable: "guildUnavailable",
597
599
  GuildUpdate: "guildUpdate",
598
600
  GuildDelete: "guildDelete",
599
601
  GuildBanAdd: "guildBanAdd",
@@ -3339,6 +3341,8 @@ var Guild = class extends Base {
3339
3341
  client;
3340
3342
  /** Snowflake ID of this guild. */
3341
3343
  id;
3344
+ /** Whether the guild is currently available through the gateway. */
3345
+ available = true;
3342
3346
  /** Guild name. */
3343
3347
  name;
3344
3348
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -3801,7 +3805,7 @@ var User = class extends Base {
3801
3805
  }
3802
3806
  /**
3803
3807
  * Send a DM to this user.
3804
- * @param options - Message content or {@link MessageSendOptions}
3808
+ * @param options - {@link MessagePrepareInput}
3805
3809
  * @returns Sent message
3806
3810
  */
3807
3811
  async send(options) {
@@ -4477,13 +4481,50 @@ function normalizeGuildPayload(raw) {
4477
4481
  }
4478
4482
 
4479
4483
  // src/client/eventHandlers/guilds.ts
4484
+ function markGuildUnavailable(client, id) {
4485
+ const guild = client.guilds.get(id);
4486
+ if (!guild || guild.available === false) return;
4487
+ guild.available = false;
4488
+ client.emit(Events.GuildUnavailable, guild);
4489
+ }
4490
+ function refreshRecoveredGuild(guild, data) {
4491
+ guild._patch(data);
4492
+ if (data.roles !== void 0) {
4493
+ guild.roles.clear();
4494
+ for (const role of data.roles) {
4495
+ guild.roles.set(role.id, new Role(guild.client, role, guild.id));
4496
+ }
4497
+ }
4498
+ if (data.channels !== void 0) {
4499
+ const recoveredChannelIds = new Set(data.channels.map((channel) => channel.id));
4500
+ for (const channel of guild.channels.values()) {
4501
+ guild.client.channels.delete(channel.id);
4502
+ if (!recoveredChannelIds.has(channel.id)) guild.client._clearMessageCache(channel.id);
4503
+ }
4504
+ guild.channels.clear();
4505
+ }
4506
+ }
4480
4507
  var guildHandlers = {
4481
4508
  GUILD_CREATE(client, d) {
4509
+ const raw = d;
4510
+ if (raw.unavailable === true) {
4511
+ if (typeof raw.id === "string") {
4512
+ try {
4513
+ markGuildUnavailable(client, raw.id);
4514
+ } finally {
4515
+ client._onGuildReceived(raw.id);
4516
+ }
4517
+ }
4518
+ return;
4519
+ }
4482
4520
  const guildData = normalizeGuildPayload(d);
4483
4521
  if (!guildData) return;
4484
- const guild = new Guild(client, guildData);
4485
- client.guilds.set(guild.id, guild);
4486
4522
  const g = d;
4523
+ const existing = client.guilds.get(guildData.id);
4524
+ const recovered = existing?.available === false;
4525
+ const guild = recovered && existing ? existing : new Guild(client, guildData);
4526
+ if (recovered) refreshRecoveredGuild(guild, g);
4527
+ client.guilds.set(guild.id, guild);
4487
4528
  for (const ch of g.channels ?? []) {
4488
4529
  const channel = Channel.from(client, ch);
4489
4530
  if (channel) {
@@ -4492,7 +4533,8 @@ var guildHandlers = {
4492
4533
  }
4493
4534
  }
4494
4535
  for (const m of g.members ?? []) cacheMember2(client, guild, m);
4495
- client.emit(Events.GuildCreate, guild);
4536
+ if (recovered) guild.available = true;
4537
+ client.emit(recovered ? Events.GuildAvailable : Events.GuildCreate, guild);
4496
4538
  if (g.voice_states?.length) {
4497
4539
  client.emit(Events.VoiceStatesSync, { guildId: guild.id, voiceStates: g.voice_states });
4498
4540
  }
@@ -4513,11 +4555,19 @@ var guildHandlers = {
4513
4555
  client.emit(Events.GuildUpdate, updated, updated);
4514
4556
  },
4515
4557
  GUILD_DELETE(client, d) {
4516
- const { id } = d;
4517
- const guild = client.guilds.get(id);
4518
- if (!guild) return;
4519
- client.guilds.delete(id);
4520
- client.emit(Events.GuildDelete, guild);
4558
+ const { id, unavailable } = d;
4559
+ try {
4560
+ if (unavailable === true) {
4561
+ markGuildUnavailable(client, id);
4562
+ return;
4563
+ }
4564
+ const guild = client.guilds.get(id);
4565
+ if (!guild) return;
4566
+ client.guilds.delete(id);
4567
+ client.emit(Events.GuildDelete, guild);
4568
+ } finally {
4569
+ client._onGuildReceived(id);
4570
+ }
4521
4571
  }
4522
4572
  };
4523
4573
 
@@ -4936,7 +4986,12 @@ function emitClientError(client, err) {
4936
4986
  function shouldDeferGatewayDispatchUntilReady(client, payload) {
4937
4987
  if (client.options.waitForGuilds !== true || client.readyAt !== null) return false;
4938
4988
  if (payload.op !== 0 || !payload.t) return false;
4939
- return payload.t !== "GUILD_CREATE";
4989
+ if (payload.t === "GUILD_CREATE") return false;
4990
+ if (payload.t === "GUILD_DELETE") {
4991
+ const data = payload.d;
4992
+ if (typeof data?.id === "string" && client._pendingGuildIds?.has(data.id)) return false;
4993
+ }
4994
+ return true;
4940
4995
  }
4941
4996
  function handleGatewayDispatch(client, payload, deferred) {
4942
4997
  if (payload.op !== 0 || !payload.t) return Promise.resolve();
package/dist/index.mjs CHANGED
@@ -468,6 +468,8 @@ var Events = {
468
468
  MessageReactionRemoveAll: "messageReactionRemoveAll",
469
469
  MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
470
470
  GuildCreate: "guildCreate",
471
+ GuildAvailable: "guildAvailable",
472
+ GuildUnavailable: "guildUnavailable",
471
473
  GuildUpdate: "guildUpdate",
472
474
  GuildDelete: "guildDelete",
473
475
  GuildBanAdd: "guildBanAdd",
@@ -3221,6 +3223,8 @@ var Guild = class extends Base {
3221
3223
  client;
3222
3224
  /** Snowflake ID of this guild. */
3223
3225
  id;
3226
+ /** Whether the guild is currently available through the gateway. */
3227
+ available = true;
3224
3228
  /** Guild name. */
3225
3229
  name;
3226
3230
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -3683,7 +3687,7 @@ var User = class extends Base {
3683
3687
  }
3684
3688
  /**
3685
3689
  * Send a DM to this user.
3686
- * @param options - Message content or {@link MessageSendOptions}
3690
+ * @param options - {@link MessagePrepareInput}
3687
3691
  * @returns Sent message
3688
3692
  */
3689
3693
  async send(options) {
@@ -4363,13 +4367,50 @@ function normalizeGuildPayload(raw) {
4363
4367
  }
4364
4368
 
4365
4369
  // src/client/eventHandlers/guilds.ts
4370
+ function markGuildUnavailable(client, id) {
4371
+ const guild = client.guilds.get(id);
4372
+ if (!guild || guild.available === false) return;
4373
+ guild.available = false;
4374
+ client.emit(Events.GuildUnavailable, guild);
4375
+ }
4376
+ function refreshRecoveredGuild(guild, data) {
4377
+ guild._patch(data);
4378
+ if (data.roles !== void 0) {
4379
+ guild.roles.clear();
4380
+ for (const role of data.roles) {
4381
+ guild.roles.set(role.id, new Role(guild.client, role, guild.id));
4382
+ }
4383
+ }
4384
+ if (data.channels !== void 0) {
4385
+ const recoveredChannelIds = new Set(data.channels.map((channel) => channel.id));
4386
+ for (const channel of guild.channels.values()) {
4387
+ guild.client.channels.delete(channel.id);
4388
+ if (!recoveredChannelIds.has(channel.id)) guild.client._clearMessageCache(channel.id);
4389
+ }
4390
+ guild.channels.clear();
4391
+ }
4392
+ }
4366
4393
  var guildHandlers = {
4367
4394
  GUILD_CREATE(client, d) {
4395
+ const raw = d;
4396
+ if (raw.unavailable === true) {
4397
+ if (typeof raw.id === "string") {
4398
+ try {
4399
+ markGuildUnavailable(client, raw.id);
4400
+ } finally {
4401
+ client._onGuildReceived(raw.id);
4402
+ }
4403
+ }
4404
+ return;
4405
+ }
4368
4406
  const guildData = normalizeGuildPayload(d);
4369
4407
  if (!guildData) return;
4370
- const guild = new Guild(client, guildData);
4371
- client.guilds.set(guild.id, guild);
4372
4408
  const g = d;
4409
+ const existing = client.guilds.get(guildData.id);
4410
+ const recovered = existing?.available === false;
4411
+ const guild = recovered && existing ? existing : new Guild(client, guildData);
4412
+ if (recovered) refreshRecoveredGuild(guild, g);
4413
+ client.guilds.set(guild.id, guild);
4373
4414
  for (const ch of g.channels ?? []) {
4374
4415
  const channel = Channel.from(client, ch);
4375
4416
  if (channel) {
@@ -4378,7 +4419,8 @@ var guildHandlers = {
4378
4419
  }
4379
4420
  }
4380
4421
  for (const m of g.members ?? []) cacheMember2(client, guild, m);
4381
- client.emit(Events.GuildCreate, guild);
4422
+ if (recovered) guild.available = true;
4423
+ client.emit(recovered ? Events.GuildAvailable : Events.GuildCreate, guild);
4382
4424
  if (g.voice_states?.length) {
4383
4425
  client.emit(Events.VoiceStatesSync, { guildId: guild.id, voiceStates: g.voice_states });
4384
4426
  }
@@ -4399,11 +4441,19 @@ var guildHandlers = {
4399
4441
  client.emit(Events.GuildUpdate, updated, updated);
4400
4442
  },
4401
4443
  GUILD_DELETE(client, d) {
4402
- const { id } = d;
4403
- const guild = client.guilds.get(id);
4404
- if (!guild) return;
4405
- client.guilds.delete(id);
4406
- client.emit(Events.GuildDelete, guild);
4444
+ const { id, unavailable } = d;
4445
+ try {
4446
+ if (unavailable === true) {
4447
+ markGuildUnavailable(client, id);
4448
+ return;
4449
+ }
4450
+ const guild = client.guilds.get(id);
4451
+ if (!guild) return;
4452
+ client.guilds.delete(id);
4453
+ client.emit(Events.GuildDelete, guild);
4454
+ } finally {
4455
+ client._onGuildReceived(id);
4456
+ }
4407
4457
  }
4408
4458
  };
4409
4459
 
@@ -4825,7 +4875,12 @@ function emitClientError(client, err) {
4825
4875
  function shouldDeferGatewayDispatchUntilReady(client, payload) {
4826
4876
  if (client.options.waitForGuilds !== true || client.readyAt !== null) return false;
4827
4877
  if (payload.op !== 0 || !payload.t) return false;
4828
- return payload.t !== "GUILD_CREATE";
4878
+ if (payload.t === "GUILD_CREATE") return false;
4879
+ if (payload.t === "GUILD_DELETE") {
4880
+ const data = payload.d;
4881
+ if (typeof data?.id === "string" && client._pendingGuildIds?.has(data.id)) return false;
4882
+ }
4883
+ return true;
4829
4884
  }
4830
4885
  function handleGatewayDispatch(client, payload, deferred) {
4831
4886
  if (payload.op !== 0 || !payload.t) return Promise.resolve();
@@ -1,4 +1,4 @@
1
- export { a2 as Message, a8 as MessageEditOptions, af as MessageSendOptions, ar as PartialMessage, aB as ReplyOptions } from './subpath-message-Acbzr5HA.mjs';
1
+ export { a2 as Message, a8 as MessageEditOptions, af as MessageSendOptions, ar as PartialMessage, aB as ReplyOptions } from './subpath-message-CoDItxh0.mjs';
2
2
  import '@fluxerjs/collection';
3
3
  import '@fluxerjs/types';
4
4
  import 'events';
package/dist/message.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { a2 as Message, a8 as MessageEditOptions, af as MessageSendOptions, ar as PartialMessage, aB as ReplyOptions } from './subpath-message-Acbzr5HA.js';
1
+ export { a2 as Message, a8 as MessageEditOptions, af as MessageSendOptions, ar as PartialMessage, aB as ReplyOptions } from './subpath-message-CoDItxh0.js';
2
2
  import '@fluxerjs/collection';
3
3
  import '@fluxerjs/types';
4
4
  import 'events';
package/dist/message.js CHANGED
@@ -246,6 +246,8 @@ var Events = {
246
246
  MessageReactionRemoveAll: "messageReactionRemoveAll",
247
247
  MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
248
248
  GuildCreate: "guildCreate",
249
+ GuildAvailable: "guildAvailable",
250
+ GuildUnavailable: "guildUnavailable",
249
251
  GuildUpdate: "guildUpdate",
250
252
  GuildDelete: "guildDelete",
251
253
  GuildBanAdd: "guildBanAdd",
package/dist/message.mjs CHANGED
@@ -223,6 +223,8 @@ var Events = {
223
223
  MessageReactionRemoveAll: "messageReactionRemoveAll",
224
224
  MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
225
225
  GuildCreate: "guildCreate",
226
+ GuildAvailable: "guildAvailable",
227
+ GuildUnavailable: "guildUnavailable",
226
228
  GuildUpdate: "guildUpdate",
227
229
  GuildDelete: "guildDelete",
228
230
  GuildBanAdd: "guildBanAdd",
@@ -715,10 +715,10 @@ declare class User extends Base {
715
715
  createDM(): Promise<DMChannel>;
716
716
  /**
717
717
  * Send a DM to this user.
718
- * @param options - Message content or {@link MessageSendOptions}
718
+ * @param options - {@link MessagePrepareInput}
719
719
  * @returns Sent message
720
720
  */
721
- send(options: MessageSendOptions): Promise<Message>;
721
+ send(options: MessagePrepareInput): Promise<Message>;
722
722
  }
723
723
 
724
724
  /** Represents a ban in a guild. */
@@ -1002,6 +1002,8 @@ declare class Guild extends Base {
1002
1002
  readonly client: Client;
1003
1003
  /** Snowflake ID of this guild. */
1004
1004
  readonly id: string;
1005
+ /** Whether the guild is currently available through the gateway. */
1006
+ available: boolean;
1005
1007
  /** Guild name. */
1006
1008
  name: string;
1007
1009
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -2392,6 +2394,8 @@ declare const Events: {
2392
2394
  readonly MessageReactionRemoveAll: "messageReactionRemoveAll";
2393
2395
  readonly MessageReactionRemoveEmoji: "messageReactionRemoveEmoji";
2394
2396
  readonly GuildCreate: "guildCreate";
2397
+ readonly GuildAvailable: "guildAvailable";
2398
+ readonly GuildUnavailable: "guildUnavailable";
2395
2399
  readonly GuildUpdate: "guildUpdate";
2396
2400
  readonly GuildDelete: "guildDelete";
2397
2401
  readonly GuildBanAdd: "guildBanAdd";
@@ -2460,6 +2464,8 @@ interface ClientEvents {
2460
2464
  [Events.MessageReactionRemoveAll]: [payload: MessageReactionRemoveAllPayload];
2461
2465
  [Events.MessageReactionRemoveEmoji]: [payload: MessageReactionRemoveEmojiPayload];
2462
2466
  [Events.GuildCreate]: [guild: Guild];
2467
+ [Events.GuildAvailable]: [guild: Guild];
2468
+ [Events.GuildUnavailable]: [guild: Guild];
2463
2469
  [Events.GuildUpdate]: [oldGuild: Guild, newGuild: Guild];
2464
2470
  [Events.GuildDelete]: [guild: Guild];
2465
2471
  /** Emitted when any channel type is created. */
@@ -715,10 +715,10 @@ declare class User extends Base {
715
715
  createDM(): Promise<DMChannel>;
716
716
  /**
717
717
  * Send a DM to this user.
718
- * @param options - Message content or {@link MessageSendOptions}
718
+ * @param options - {@link MessagePrepareInput}
719
719
  * @returns Sent message
720
720
  */
721
- send(options: MessageSendOptions): Promise<Message>;
721
+ send(options: MessagePrepareInput): Promise<Message>;
722
722
  }
723
723
 
724
724
  /** Represents a ban in a guild. */
@@ -1002,6 +1002,8 @@ declare class Guild extends Base {
1002
1002
  readonly client: Client;
1003
1003
  /** Snowflake ID of this guild. */
1004
1004
  readonly id: string;
1005
+ /** Whether the guild is currently available through the gateway. */
1006
+ available: boolean;
1005
1007
  /** Guild name. */
1006
1008
  name: string;
1007
1009
  /** Icon hash (use {@link iconURL} to get full CDN URL). */
@@ -2392,6 +2394,8 @@ declare const Events: {
2392
2394
  readonly MessageReactionRemoveAll: "messageReactionRemoveAll";
2393
2395
  readonly MessageReactionRemoveEmoji: "messageReactionRemoveEmoji";
2394
2396
  readonly GuildCreate: "guildCreate";
2397
+ readonly GuildAvailable: "guildAvailable";
2398
+ readonly GuildUnavailable: "guildUnavailable";
2395
2399
  readonly GuildUpdate: "guildUpdate";
2396
2400
  readonly GuildDelete: "guildDelete";
2397
2401
  readonly GuildBanAdd: "guildBanAdd";
@@ -2460,6 +2464,8 @@ interface ClientEvents {
2460
2464
  [Events.MessageReactionRemoveAll]: [payload: MessageReactionRemoveAllPayload];
2461
2465
  [Events.MessageReactionRemoveEmoji]: [payload: MessageReactionRemoveEmojiPayload];
2462
2466
  [Events.GuildCreate]: [guild: Guild];
2467
+ [Events.GuildAvailable]: [guild: Guild];
2468
+ [Events.GuildUnavailable]: [guild: Guild];
2463
2469
  [Events.GuildUpdate]: [oldGuild: Guild, newGuild: Guild];
2464
2470
  [Events.GuildDelete]: [guild: Guild];
2465
2471
  /** Emitted when any channel type is created. */
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.0.0",
6
+ "version": "2.0.2",
7
7
  "description": "A fully-featured SDK for Fluxer bots",
8
8
  "repository": {
9
9
  "type": "git",
@@ -54,8 +54,8 @@
54
54
  "dist"
55
55
  ],
56
56
  "dependencies": {
57
- "@fluxerjs/rest": "2.0.0",
58
- "@fluxerjs/ws": "2.0.0",
57
+ "@fluxerjs/rest": "2.0.2",
58
+ "@fluxerjs/ws": "2.0.1",
59
59
  "@fluxerjs/builders": "2.0.0",
60
60
  "@fluxerjs/collection": "2.0.0",
61
61
  "@fluxerjs/util": "2.0.0",