discord.js 15.0.0-dev.1746576824-432cdbe88 → 15.0.0-dev.1746792317-4f6fedfb1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "discord.js",
4
- "version": "15.0.0-dev.1746576824-432cdbe88",
4
+ "version": "15.0.0-dev.1746792317-4f6fedfb1",
5
5
  "description": "A powerful library for interacting with the Discord API",
6
6
  "main": "./src/index.js",
7
7
  "types": "./typings/index.d.ts",
@@ -23,7 +23,8 @@
23
23
  },
24
24
  "files": [
25
25
  "src",
26
- "typings"
26
+ "typings/*.d.ts",
27
+ "typings/*.d.mts"
27
28
  ],
28
29
  "contributors": [
29
30
  "Crawl <icrawltogo@gmail.com>",
@@ -60,12 +61,12 @@
60
61
  "magic-bytes.js": "^1.10.0",
61
62
  "tslib": "^2.8.1",
62
63
  "undici": "7.8.0",
64
+ "@discordjs/builders": "^1.11.1",
65
+ "@discordjs/formatters": "^0.6.1",
63
66
  "@discordjs/collection": "^2.1.1",
64
67
  "@discordjs/rest": "^2.5.0",
65
68
  "@discordjs/util": "^1.1.1",
66
- "@discordjs/formatters": "^0.6.1",
67
- "@discordjs/ws": "^2.0.2",
68
- "@discordjs/builders": "^1.11.1"
69
+ "@discordjs/ws": "^2.0.2"
69
70
  },
70
71
  "devDependencies": {
71
72
  "@favware/cliff-jumper": "^4.1.0",
@@ -73,6 +73,13 @@ class ChannelManager extends CachedManager {
73
73
 
74
74
  channel?.parent?.threads?.cache.delete(id);
75
75
  this.cache.delete(id);
76
+
77
+ if (channel?.threads) {
78
+ for (const threadId of channel.threads.cache.keys()) {
79
+ this.cache.delete(threadId);
80
+ channel.guild?.channels.cache.delete(threadId);
81
+ }
82
+ }
76
83
  }
77
84
 
78
85
  /**
@@ -285,8 +285,8 @@ class GuildManager extends CachedManager {
285
285
 
286
286
  /**
287
287
  * @typedef {Object} FetchSoundboardSoundsOptions
288
- * @param {Snowflake[]} guildIds The ids of the guilds to fetch soundboard sounds for
289
- * @param {number} [time=10_000] The timeout for receipt of the soundboard sounds
288
+ * @property {Snowflake[]} guildIds The ids of the guilds to fetch soundboard sounds for
289
+ * @property {number} [time=10_000] The timeout for receipt of the soundboard sounds
290
290
  */
291
291
 
292
292
  /**
@@ -105,7 +105,7 @@ class GuildSoundboardSoundManager extends CachedManager {
105
105
  * Data for editing a soundboard sound.
106
106
  * @typedef {Object} GuildSoundboardSoundEditOptions
107
107
  * @property {string} [name] The name of the soundboard sound
108
- * @property {?number} [volume] The volume of the soundboard sound, from 0 to 1
108
+ * @property {?number} [volume] The volume (a double) of the soundboard sound, from 0 (inclusive) to 1
109
109
  * @property {?Snowflake} [emojiId] The emoji id of the soundboard sound
110
110
  * @property {?string} [emojiName] The emoji name of the soundboard sound
111
111
  * @property {string} [reason] The reason for editing the soundboard sound
@@ -157,35 +157,57 @@ class GuildSoundboardSoundManager extends CachedManager {
157
157
  await this.client.rest.delete(Routes.guildSoundboardSound(this.guild.id, soundId), { reason });
158
158
  }
159
159
 
160
+ /**
161
+ * Options used to fetch a soundboard sound.
162
+ * @typedef {BaseFetchOptions} FetchSoundboardSoundOptions
163
+ * @property {SoundboardSoundResolvable} soundboardSound The soundboard sound to fetch
164
+ */
165
+
166
+ /**
167
+ * Options used to fetch soundboard sounds from Discord
168
+ * @typedef {Object} FetchGuildSoundboardSoundsOptions
169
+ * @property {boolean} [cache] Whether to cache the fetched soundboard sounds
170
+ */
171
+
172
+ /* eslint-disable max-len */
160
173
  /**
161
174
  * Obtains one or more soundboard sounds from Discord, or the soundboard sound cache if they're already available.
162
- * @param {Snowflake} [id] The soundboard sound's id
163
- * @param {BaseFetchOptions} [options] Additional options for this fetch
175
+ * @param {SoundboardSoundResolvable|FetchSoundboardSoundOptions|FetchGuildSoundboardSoundsOptions} [options] Options for fetching soundboard sound(s)
164
176
  * @returns {Promise<SoundboardSound|Collection<Snowflake, SoundboardSound>>}
165
177
  * @example
166
- * // Fetch all soundboard sounds from the guild
167
- * guild.soundboardSounds.fetch()
168
- * .then(sounds => console.log(`There are ${sounds.size} soundboard sounds.`))
169
- * .catch(console.error);
170
- * @example
171
178
  * // Fetch a single soundboard sound
172
179
  * guild.soundboardSounds.fetch('222078108977594368')
173
180
  * .then(sound => console.log(`The soundboard sound name is: ${sound.name}`))
174
181
  * .catch(console.error);
182
+ * @example
183
+ * // Fetch all soundboard sounds from the guild
184
+ * guild.soundboardSounds.fetch()
185
+ * .then(sounds => console.log(`There are ${sounds.size} soundboard sounds.`))
186
+ * .catch(console.error);
175
187
  */
176
- async fetch(id, { cache = true, force = false } = {}) {
177
- if (id) {
178
- if (!force) {
179
- const existing = this.cache.get(id);
180
- if (existing) return existing;
181
- }
182
-
183
- const sound = await this.client.rest.get(Routes.guildSoundboardSound(this.guild.id, id));
184
- return this._add(sound, cache);
188
+ /* eslint-enable max-len */
189
+ async fetch(options) {
190
+ if (!options) return this._fetchMany();
191
+ const { cache, force, soundboardSound } = options;
192
+ const resolvedSoundboardSound = this.resolveId(soundboardSound ?? options);
193
+ if (resolvedSoundboardSound) return this._fetchSingle({ cache, force, soundboardSound: resolvedSoundboardSound });
194
+ return this._fetchMany({ cache });
195
+ }
196
+
197
+ async _fetchSingle({ cache, force, soundboardSound } = {}) {
198
+ if (!force) {
199
+ const existing = this.cache.get(soundboardSound);
200
+ if (existing) return existing;
185
201
  }
186
202
 
203
+ const data = await this.client.rest.get(Routes.guildSoundboardSound(this.guild.id, soundboardSound));
204
+ return this._add(data, cache);
205
+ }
206
+
207
+ async _fetchMany({ cache } = {}) {
187
208
  const data = await this.client.rest.get(Routes.guildSoundboardSounds(this.guild.id));
188
- return new Collection(data.map(sound => [sound.sound_id, this._add(sound, cache)]));
209
+
210
+ return data.items.reduce((coll, sound) => coll.set(sound.sound_id, this._add(sound, cache)), new Collection());
189
211
  }
190
212
  }
191
213
 
@@ -489,6 +489,13 @@ class Guild extends AnonymousGuild {
489
489
  } else {
490
490
  this.incidentsData ??= null;
491
491
  }
492
+
493
+ if (data.soundboard_sounds) {
494
+ this.soundboardSounds.cache.clear();
495
+ for (const soundboardSound of data.soundboard_sounds) {
496
+ this.soundboardSounds._add(soundboardSound);
497
+ }
498
+ }
492
499
  }
493
500
 
494
501
  /**
@@ -27,7 +27,7 @@ class PartialGroupDMChannel extends BaseChannel {
27
27
  * The hash of the channel icon
28
28
  * @type {?string}
29
29
  */
30
- this.icon = data.icon;
30
+ this.icon = data.icon ?? null;
31
31
 
32
32
  /**
33
33
  * Recipient data received in a {@link PartialGroupDMChannel}.
@@ -39,7 +39,7 @@ class PartialGroupDMChannel extends BaseChannel {
39
39
  * The recipients of this Group DM Channel.
40
40
  * @type {PartialRecipient[]}
41
41
  */
42
- this.recipients = data.recipients;
42
+ this.recipients = data.recipients ?? [];
43
43
 
44
44
  /**
45
45
  * A manager of the messages belonging to this channel
@@ -181,8 +181,8 @@ class SoundboardSound extends Base {
181
181
  this.available === other.available &&
182
182
  this.name === other.name &&
183
183
  this.volume === other.volume &&
184
- this.emojiId === other.emojiId &&
185
- this.emojiName === other.emojiName &&
184
+ this._emoji?.id === other._emoji?.id &&
185
+ this._emoji?.name === other._emoji?.name &&
186
186
  this.guildId === other.guildId &&
187
187
  this.user?.id === other.user?.id
188
188
  );
@@ -193,8 +193,8 @@ class SoundboardSound extends Base {
193
193
  this.available === other.available &&
194
194
  this.name === other.name &&
195
195
  this.volume === other.volume &&
196
- this.emojiId === other.emoji_id &&
197
- this.emojiName === other.emoji_name &&
196
+ (this._emoji?.id ?? null) === other.emoji_id &&
197
+ (this._emoji?.name ?? null) === other.emoji_name &&
198
198
  this.guildId === other.guild_id &&
199
199
  this.user?.id === other.user?.id
200
200
  );
@@ -68,30 +68,7 @@ const { ComponentType } = require('discord-api-types/v10');
68
68
  * @ignore
69
69
  */
70
70
  function createComponent(data) {
71
- if (data instanceof Component) {
72
- return data;
73
- }
74
-
75
- switch (data.type) {
76
- case ComponentType.ActionRow:
77
- return new ActionRow(data);
78
- case ComponentType.Button:
79
- return new ButtonComponent(data);
80
- case ComponentType.StringSelect:
81
- return new StringSelectMenuComponent(data);
82
- case ComponentType.TextInput:
83
- return new TextInputComponent(data);
84
- case ComponentType.UserSelect:
85
- return new UserSelectMenuComponent(data);
86
- case ComponentType.RoleSelect:
87
- return new RoleSelectMenuComponent(data);
88
- case ComponentType.MentionableSelect:
89
- return new MentionableSelectMenuComponent(data);
90
- case ComponentType.ChannelSelect:
91
- return new ChannelSelectMenuComponent(data);
92
- default:
93
- return new Component(data);
94
- }
71
+ return data instanceof Component ? data : new (ComponentTypeToClass[data.type] ?? Component)(data);
95
72
  }
96
73
 
97
74
  exports.createComponent = createComponent;
@@ -105,3 +82,14 @@ const { RoleSelectMenuComponent } = require('../structures/RoleSelectMenuCompone
105
82
  const { StringSelectMenuComponent } = require('../structures/StringSelectMenuComponent.js');
106
83
  const { TextInputComponent } = require('../structures/TextInputComponent.js');
107
84
  const { UserSelectMenuComponent } = require('../structures/UserSelectMenuComponent.js');
85
+
86
+ const ComponentTypeToClass = {
87
+ [ComponentType.ActionRow]: ActionRow,
88
+ [ComponentType.Button]: ButtonComponent,
89
+ [ComponentType.StringSelect]: StringSelectMenuComponent,
90
+ [ComponentType.TextInput]: TextInputComponent,
91
+ [ComponentType.UserSelect]: UserSelectMenuComponent,
92
+ [ComponentType.RoleSelect]: RoleSelectMenuComponent,
93
+ [ComponentType.MentionableSelect]: MentionableSelectMenuComponent,
94
+ [ComponentType.ChannelSelect]: ChannelSelectMenuComponent,
95
+ };
@@ -4290,8 +4290,15 @@ export interface GuildSoundboardSoundEditOptions {
4290
4290
  volume?: number | null;
4291
4291
  emojiId?: Snowflake | null;
4292
4292
  emojiName?: string | null;
4293
+ reason?: string;
4294
+ }
4295
+
4296
+ export interface FetchGuildSoundboardSoundOptions extends BaseFetchOptions {
4297
+ soundboardSound: SoundboardSoundResolvable;
4293
4298
  }
4294
4299
 
4300
+ export interface FetchGuildSoundboardSoundsOptions extends Pick<BaseFetchOptions, 'cache'> {}
4301
+
4295
4302
  export class GuildSoundboardSoundManager extends CachedManager<Snowflake, SoundboardSound, SoundboardSoundResolvable> {
4296
4303
  private constructor(guild: Guild, iterable?: Iterable<APISoundboardSound>);
4297
4304
  public guild: Guild;
@@ -5804,8 +5811,7 @@ export interface GuildAuditLogsEntryTargetField<TAction extends AuditLogEvent> {
5804
5811
  ApplicationCommand: ApplicationCommand | { id: Snowflake };
5805
5812
  AutoModeration: AutoModerationRule;
5806
5813
  GuildOnboardingPrompt: GuildOnboardingPrompt | { id: Snowflake; [x: string]: unknown };
5807
- // TODO: Update when https://github.com/discordjs/discord.js/pull/10590 is merged
5808
- SoundboardSound: { id: Snowflake };
5814
+ SoundboardSound: SoundboardSound | { id: Snowflake };
5809
5815
  }
5810
5816
 
5811
5817
  export interface GuildAuditLogsFetchOptions<Event extends GuildAuditLogsResolvable> {
@@ -4290,8 +4290,15 @@ export interface GuildSoundboardSoundEditOptions {
4290
4290
  volume?: number | null;
4291
4291
  emojiId?: Snowflake | null;
4292
4292
  emojiName?: string | null;
4293
+ reason?: string;
4294
+ }
4295
+
4296
+ export interface FetchGuildSoundboardSoundOptions extends BaseFetchOptions {
4297
+ soundboardSound: SoundboardSoundResolvable;
4293
4298
  }
4294
4299
 
4300
+ export interface FetchGuildSoundboardSoundsOptions extends Pick<BaseFetchOptions, 'cache'> {}
4301
+
4295
4302
  export class GuildSoundboardSoundManager extends CachedManager<Snowflake, SoundboardSound, SoundboardSoundResolvable> {
4296
4303
  private constructor(guild: Guild, iterable?: Iterable<APISoundboardSound>);
4297
4304
  public guild: Guild;
@@ -5804,8 +5811,7 @@ export interface GuildAuditLogsEntryTargetField<TAction extends AuditLogEvent> {
5804
5811
  ApplicationCommand: ApplicationCommand | { id: Snowflake };
5805
5812
  AutoModeration: AutoModerationRule;
5806
5813
  GuildOnboardingPrompt: GuildOnboardingPrompt | { id: Snowflake; [x: string]: unknown };
5807
- // TODO: Update when https://github.com/discordjs/discord.js/pull/10590 is merged
5808
- SoundboardSound: { id: Snowflake };
5814
+ SoundboardSound: SoundboardSound | { id: Snowflake };
5809
5815
  }
5810
5816
 
5811
5817
  export interface GuildAuditLogsFetchOptions<Event extends GuildAuditLogsResolvable> {