discord.js 15.0.0-dev.1737763893-2cbf41800 → 15.0.0-dev.1737893061-0ab6abbcf

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.1737763893-2cbf41800",
4
+ "version": "15.0.0-dev.1737893061-0ab6abbcf",
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",
@@ -60,11 +60,11 @@
60
60
  "lodash.snakecase": "4.1.1",
61
61
  "tslib": "^2.8.1",
62
62
  "undici": "6.21.0",
63
- "@discordjs/collection": "^2.1.1",
64
63
  "@discordjs/formatters": "^0.5.0",
64
+ "@discordjs/collection": "^2.1.1",
65
65
  "@discordjs/util": "^1.1.1",
66
- "@discordjs/ws": "^2.0.0",
67
- "@discordjs/rest": "^2.4.0"
66
+ "@discordjs/rest": "^2.4.0",
67
+ "@discordjs/ws": "^2.0.0"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@favware/cliff-jumper": "^4.1.0",
@@ -81,9 +81,9 @@
81
81
  "tslint": "6.1.3",
82
82
  "turbo": "^2.3.3",
83
83
  "typescript": "~5.5.4",
84
- "@discordjs/api-extractor": "^7.38.1",
84
+ "@discordjs/docgen": "^0.12.1",
85
85
  "@discordjs/scripts": "^0.1.0",
86
- "@discordjs/docgen": "^0.12.1"
86
+ "@discordjs/api-extractor": "^7.38.1"
87
87
  },
88
88
  "engines": {
89
89
  "node": ">=20"
@@ -81,6 +81,7 @@ class ApplicationCommandManager extends CachedManager {
81
81
  /**
82
82
  * Options used to fetch Application Commands from Discord
83
83
  * @typedef {BaseFetchOptions} FetchApplicationCommandOptions
84
+ * @property {Snowflake} [id] The command's id to fetch
84
85
  * @property {Snowflake} [guildId] The guild's id to fetch commands for, for when the guild is not cached
85
86
  * @property {Locale} [locale] The locale to use when fetching this command
86
87
  * @property {boolean} [withLocalizations] Whether to fetch all localization data
@@ -88,8 +89,7 @@ class ApplicationCommandManager extends CachedManager {
88
89
 
89
90
  /**
90
91
  * Obtains one or multiple application commands from Discord, or the cache if it's already available.
91
- * @param {Snowflake|FetchApplicationCommandOptions} [id] Options for fetching application command(s)
92
- * @param {FetchApplicationCommandOptions} [options] Additional options for this fetch
92
+ * @param {Snowflake|FetchApplicationCommandOptions} [options] Options for fetching application command(s)
93
93
  * @returns {Promise<ApplicationCommand|Collection<Snowflake, ApplicationCommand>>}
94
94
  * @example
95
95
  * // Fetch a single command
@@ -98,28 +98,50 @@ class ApplicationCommandManager extends CachedManager {
98
98
  * .catch(console.error);
99
99
  * @example
100
100
  * // Fetch all commands
101
+ * client.application.commands.fetch()
102
+ * .then(commands => console.log(`Fetched ${commands.size} commands`))
103
+ * .catch(console.error);
104
+ * @example
105
+ * // Fetch all commands in a guild
101
106
  * guild.commands.fetch()
102
107
  * .then(commands => console.log(`Fetched ${commands.size} commands`))
103
108
  * .catch(console.error);
109
+ * @example
110
+ * // Fetch a single command without checking cache
111
+ * guild.commands.fetch({ id: '123456789012345678', force: true })
112
+ * .then(command => console.log(`Fetched command ${command.name}`))
113
+ * .catch(console.error)
104
114
  */
105
- async fetch(id, { guildId, cache = true, force = false, locale, withLocalizations } = {}) {
106
- if (typeof id === 'object') {
107
- ({ guildId, cache = true, locale, withLocalizations } = id);
108
- } else if (id) {
109
- if (!force) {
110
- const existing = this.cache.get(id);
111
- if (existing) return existing;
112
- }
113
- const command = await this.client.rest.get(this.commandPath({ id, guildId }));
114
- return this._add(command, cache);
115
+ async fetch(options) {
116
+ if (!options) return this._fetchMany();
117
+
118
+ if (typeof options === 'string') return this._fetchSingle({ id: options });
119
+
120
+ const { cache, force, guildId, id, locale, withLocalizations } = options;
121
+
122
+ if (id) return this._fetchSingle({ cache, force, guildId, id });
123
+
124
+ return this._fetchMany({ cache, guildId, locale, withLocalizations });
125
+ }
126
+
127
+ async _fetchSingle({ cache, force = false, guildId, id }) {
128
+ if (!force) {
129
+ const existing = this.cache.get(id);
130
+ if (existing) return existing;
115
131
  }
116
132
 
133
+ const command = await this.client.rest.get(this.commandPath({ id, guildId }));
134
+ return this._add(command, cache);
135
+ }
136
+
137
+ async _fetchMany({ cache, guildId, locale, withLocalizations } = {}) {
117
138
  const data = await this.client.rest.get(this.commandPath({ guildId }), {
118
139
  headers: {
119
140
  'X-Discord-Locale': locale,
120
141
  },
121
142
  query: makeURLSearchParams({ with_localizations: withLocalizations }),
122
143
  });
144
+
123
145
  return data.reduce((coll, command) => coll.set(command.id, this._add(command, cache, guildId)), new Collection());
124
146
  }
125
147
 
@@ -41,15 +41,12 @@ class GuildScheduledEventManager extends CachedManager {
41
41
  * Options for setting a recurrence rule for a guild scheduled event.
42
42
  * @typedef {Object} GuildScheduledEventRecurrenceRuleOptions
43
43
  * @property {DateResolvable} startAt The time the recurrence rule interval starts at
44
- * @property {?DateResolvable} endAt The time the recurrence rule interval ends at
45
44
  * @property {GuildScheduledEventRecurrenceRuleFrequency} frequency How often the event occurs
46
45
  * @property {number} interval The spacing between the events
47
46
  * @property {?GuildScheduledEventRecurrenceRuleWeekday[]} byWeekday The days within a week to recur on
48
47
  * @property {?GuildScheduledEventRecurrenceRuleNWeekday[]} byNWeekday The days within a week to recur on
49
48
  * @property {?GuildScheduledEventRecurrenceRuleMonth[]} byMonth The months to recur on
50
49
  * @property {?number[]} byMonthDay The days within a month to recur on
51
- * @property {?number[]} byYearDay The days within a year to recur on
52
- * @property {?number} count The total amount of times the event is allowed to recur before stopping
53
50
  */
54
51
 
55
52
  /**
@@ -63,16 +63,12 @@ function _transformAPIMessageInteractionMetadata(client, messageInteractionMetad
63
63
  function _transformGuildScheduledEventRecurrenceRule(recurrenceRule) {
64
64
  return {
65
65
  start: new Date(recurrenceRule.startAt).toISOString(),
66
- // eslint-disable-next-line eqeqeq
67
- end: recurrenceRule.endAt != null ? new Date(recurrenceRule.endAt).toISOString() : recurrenceRule.endAt,
68
66
  frequency: recurrenceRule.frequency,
69
67
  interval: recurrenceRule.interval,
70
68
  by_weekday: recurrenceRule.byWeekday,
71
69
  by_n_weekday: recurrenceRule.byNWeekday,
72
70
  by_month: recurrenceRule.byMonth,
73
71
  by_month_day: recurrenceRule.byMonthDay,
74
- by_year_day: recurrenceRule.byYearDay,
75
- count: recurrenceRule.count,
76
72
  };
77
73
  }
78
74
 
@@ -3913,14 +3913,13 @@ export class ApplicationCommandManager<
3913
3913
  guildId: Snowflake,
3914
3914
  ): Promise<ApplicationCommand>;
3915
3915
  public fetch(
3916
- id: Snowflake,
3917
- options: FetchApplicationCommandOptions & { guildId: Snowflake },
3916
+ options: Snowflake | (Omit<FetchApplicationCommandOptions, 'guildId'> & { id: Snowflake }),
3917
+ ): Promise<ApplicationCommandScope>;
3918
+ public fetch(
3919
+ options: FetchApplicationCommandOptions & { id: Snowflake; guildId: Snowflake },
3918
3920
  ): Promise<ApplicationCommand>;
3919
- public fetch(options: FetchApplicationCommandOptions): Promise<Collection<Snowflake, ApplicationCommandScope>>;
3920
- public fetch(id: Snowflake, options?: FetchApplicationCommandOptions): Promise<ApplicationCommandScope>;
3921
3921
  public fetch(
3922
- id?: Snowflake,
3923
- options?: FetchApplicationCommandOptions,
3922
+ options?: Omit<FetchApplicationCommandOptions, 'id'>,
3924
3923
  ): Promise<Collection<Snowflake, ApplicationCommandScope>>;
3925
3924
  public set(
3926
3925
  commands: readonly ApplicationCommandDataResolvable[],
@@ -4089,11 +4088,11 @@ export class GuildApplicationCommandManager extends ApplicationCommandManager<Ap
4089
4088
  command: ApplicationCommandResolvable,
4090
4089
  data: Partial<ApplicationCommandDataResolvable>,
4091
4090
  ): Promise<ApplicationCommand>;
4092
- public fetch(id: Snowflake, options?: FetchGuildApplicationCommandFetchOptions): Promise<ApplicationCommand>;
4093
- public fetch(options: FetchGuildApplicationCommandFetchOptions): Promise<Collection<Snowflake, ApplicationCommand>>;
4094
4091
  public fetch(
4095
- id?: undefined,
4096
- options?: FetchGuildApplicationCommandFetchOptions,
4092
+ options: Snowflake | (FetchGuildApplicationCommandFetchOptions & { id: Snowflake }),
4093
+ ): Promise<ApplicationCommand>;
4094
+ public fetch(
4095
+ options?: Omit<FetchGuildApplicationCommandFetchOptions, 'id'>,
4097
4096
  ): Promise<Collection<Snowflake, ApplicationCommand>>;
4098
4097
  public set(commands: readonly ApplicationCommandDataResolvable[]): Promise<Collection<Snowflake, ApplicationCommand>>;
4099
4098
  }
@@ -5461,6 +5460,7 @@ export type EmojiIdentifierResolvable =
5461
5460
  export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji | ApplicationEmoji;
5462
5461
 
5463
5462
  export interface FetchApplicationCommandOptions extends BaseFetchOptions {
5463
+ id?: Snowflake;
5464
5464
  guildId?: Snowflake;
5465
5465
  locale?: Locale;
5466
5466
  withLocalizations?: boolean;
@@ -5979,8 +5979,6 @@ type BaseGuildScheduledEventRecurrenceRuleOptions<
5979
5979
  Extra extends {},
5980
5980
  > = {
5981
5981
  startAt: DateResolvable;
5982
- endAt?: DateResolvable;
5983
- count?: number;
5984
5982
  interval: number;
5985
5983
  frequency: Frequency;
5986
5984
  } & Extra;
@@ -3913,14 +3913,13 @@ export class ApplicationCommandManager<
3913
3913
  guildId: Snowflake,
3914
3914
  ): Promise<ApplicationCommand>;
3915
3915
  public fetch(
3916
- id: Snowflake,
3917
- options: FetchApplicationCommandOptions & { guildId: Snowflake },
3916
+ options: Snowflake | (Omit<FetchApplicationCommandOptions, 'guildId'> & { id: Snowflake }),
3917
+ ): Promise<ApplicationCommandScope>;
3918
+ public fetch(
3919
+ options: FetchApplicationCommandOptions & { id: Snowflake; guildId: Snowflake },
3918
3920
  ): Promise<ApplicationCommand>;
3919
- public fetch(options: FetchApplicationCommandOptions): Promise<Collection<Snowflake, ApplicationCommandScope>>;
3920
- public fetch(id: Snowflake, options?: FetchApplicationCommandOptions): Promise<ApplicationCommandScope>;
3921
3921
  public fetch(
3922
- id?: Snowflake,
3923
- options?: FetchApplicationCommandOptions,
3922
+ options?: Omit<FetchApplicationCommandOptions, 'id'>,
3924
3923
  ): Promise<Collection<Snowflake, ApplicationCommandScope>>;
3925
3924
  public set(
3926
3925
  commands: readonly ApplicationCommandDataResolvable[],
@@ -4089,11 +4088,11 @@ export class GuildApplicationCommandManager extends ApplicationCommandManager<Ap
4089
4088
  command: ApplicationCommandResolvable,
4090
4089
  data: Partial<ApplicationCommandDataResolvable>,
4091
4090
  ): Promise<ApplicationCommand>;
4092
- public fetch(id: Snowflake, options?: FetchGuildApplicationCommandFetchOptions): Promise<ApplicationCommand>;
4093
- public fetch(options: FetchGuildApplicationCommandFetchOptions): Promise<Collection<Snowflake, ApplicationCommand>>;
4094
4091
  public fetch(
4095
- id?: undefined,
4096
- options?: FetchGuildApplicationCommandFetchOptions,
4092
+ options: Snowflake | (FetchGuildApplicationCommandFetchOptions & { id: Snowflake }),
4093
+ ): Promise<ApplicationCommand>;
4094
+ public fetch(
4095
+ options?: Omit<FetchGuildApplicationCommandFetchOptions, 'id'>,
4097
4096
  ): Promise<Collection<Snowflake, ApplicationCommand>>;
4098
4097
  public set(commands: readonly ApplicationCommandDataResolvable[]): Promise<Collection<Snowflake, ApplicationCommand>>;
4099
4098
  }
@@ -5461,6 +5460,7 @@ export type EmojiIdentifierResolvable =
5461
5460
  export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji | ApplicationEmoji;
5462
5461
 
5463
5462
  export interface FetchApplicationCommandOptions extends BaseFetchOptions {
5463
+ id?: Snowflake;
5464
5464
  guildId?: Snowflake;
5465
5465
  locale?: Locale;
5466
5466
  withLocalizations?: boolean;
@@ -5979,8 +5979,6 @@ type BaseGuildScheduledEventRecurrenceRuleOptions<
5979
5979
  Extra extends {},
5980
5980
  > = {
5981
5981
  startAt: DateResolvable;
5982
- endAt?: DateResolvable;
5983
- count?: number;
5984
5982
  interval: number;
5985
5983
  frequency: Frequency;
5986
5984
  } & Extra;
@@ -712,8 +712,8 @@ client.on('clientReady', async client => {
712
712
 
713
713
  // Test command manager methods
714
714
  const globalCommand = await client.application?.commands.fetch(globalCommandId);
715
- const guildCommandFromGlobal = await client.application?.commands.fetch(guildCommandId, { guildId: testGuildId });
716
- const guildCommandFromGuild = await client.guilds.cache.get(testGuildId)?.commands.fetch(guildCommandId);
715
+ const guildCommandFromGlobal = await client.application?.commands.fetch({ id: guildCommandId, guildId: testGuildId });
716
+ const guildCommandFromGuild = await client.guilds.cache.get(testGuildId)?.commands.fetch({ id: guildCommandId });
717
717
 
718
718
  await client.application?.commands.create(slashCommandBuilder);
719
719
  await client.application?.commands.create(contextMenuCommandBuilder);
@@ -1589,9 +1589,9 @@ declare const autoModerationRuleManager: AutoModerationRuleManager;
1589
1589
  }
1590
1590
 
1591
1591
  declare const guildApplicationCommandManager: GuildApplicationCommandManager;
1592
- expectType<Promise<Collection<Snowflake, ApplicationCommand>>>(guildApplicationCommandManager.fetch());
1593
- expectType<Promise<Collection<Snowflake, ApplicationCommand>>>(guildApplicationCommandManager.fetch(undefined, {}));
1594
1592
  expectType<Promise<ApplicationCommand>>(guildApplicationCommandManager.fetch('0'));
1593
+ expectType<Promise<ApplicationCommand>>(guildApplicationCommandManager.fetch({ id: '0' }));
1594
+ expectType<Promise<Collection<Snowflake, ApplicationCommand>>>(guildApplicationCommandManager.fetch());
1595
1595
 
1596
1596
  declare const categoryChannelChildManager: CategoryChannelChildManager;
1597
1597
  {