discord.js 15.0.0-dev.1733357584-d0dc86488 → 15.0.0-dev.1733443983-00dceb32b

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.1733357584-d0dc86488",
4
+ "version": "15.0.0-dev.1733443983-00dceb32b",
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,9 +60,9 @@
60
60
  "lodash.snakecase": "4.1.1",
61
61
  "tslib": "^2.8.1",
62
62
  "undici": "6.21.0",
63
+ "@discordjs/formatters": "^0.5.0",
63
64
  "@discordjs/rest": "^2.4.0",
64
65
  "@discordjs/ws": "^2.0.0",
65
- "@discordjs/formatters": "^0.5.0",
66
66
  "@discordjs/util": "^1.1.1"
67
67
  },
68
68
  "devDependencies": {
@@ -81,8 +81,8 @@
81
81
  "turbo": "^2.3.0",
82
82
  "typescript": "~5.5.4",
83
83
  "@discordjs/docgen": "^0.12.1",
84
- "@discordjs/api-extractor": "^7.38.1",
85
- "@discordjs/scripts": "^0.1.0"
84
+ "@discordjs/scripts": "^0.1.0",
85
+ "@discordjs/api-extractor": "^7.38.1"
86
86
  },
87
87
  "engines": {
88
88
  "node": ">=20"
@@ -196,7 +196,7 @@ class Client extends BaseClient {
196
196
 
197
197
  /**
198
198
  * The last time a ping was sent (a timestamp) for each WebSocketShard connection
199
- * @type {Collection<number,number>}
199
+ * @type {Collection<number, number>}
200
200
  */
201
201
  this.lastPingTimestamps = new Collection();
202
202
 
@@ -37,6 +37,12 @@ class EntitlementManager extends CachedManager {
37
37
  * @typedef {SKU|Snowflake} SKUResolvable
38
38
  */
39
39
 
40
+ /**
41
+ * Options used to fetch an entitlement
42
+ * @typedef {BaseFetchOptions} FetchEntitlementOptions
43
+ * @property {EntitlementResolvable} entitlement The entitlement to fetch
44
+ */
45
+
40
46
  /**
41
47
  * Options used to fetch entitlements
42
48
  * @typedef {Object} FetchEntitlementsOptions
@@ -45,6 +51,7 @@ class EntitlementManager extends CachedManager {
45
51
  * @property {UserResolvable} [user] The user to fetch entitlements for
46
52
  * @property {SKUResolvable[]} [skus] The SKUs to fetch entitlements for
47
53
  * @property {boolean} [excludeEnded] Whether to exclude ended entitlements
54
+ * @property {boolean} [excludeDeleted] Whether to exclude deleted entitlements
48
55
  * @property {boolean} [cache=true] Whether to cache the fetched entitlements
49
56
  * @property {Snowflake} [before] Consider only entitlements before this entitlement id
50
57
  * @property {Snowflake} [after] Consider only entitlements after this entitlement id
@@ -53,21 +60,49 @@ class EntitlementManager extends CachedManager {
53
60
 
54
61
  /**
55
62
  * Fetches entitlements for this application
56
- * @param {FetchEntitlementsOptions} [options={}] Options for fetching the entitlements
57
- * @returns {Promise<Collection<Snowflake, Entitlement>>}
63
+ * @param {EntitlementResolvable|FetchEntitlementOptions|FetchEntitlementsOptions} [options]
64
+ * Options for fetching the entitlements
65
+ * @returns {Promise<Entitlement|Collection<Snowflake, Entitlement>>}
58
66
  */
59
- async fetch({ limit, guild, user, skus, excludeEnded, cache = true, before, after } = {}) {
67
+ async fetch(options) {
68
+ if (!options) return this._fetchMany(options);
69
+ const { entitlement, cache, force } = options;
70
+ const resolvedEntitlement = this.resolveId(entitlement ?? options);
71
+
72
+ if (resolvedEntitlement) {
73
+ return this._fetchSingle({ entitlement: resolvedEntitlement, cache, force });
74
+ }
75
+
76
+ return this._fetchMany(options);
77
+ }
78
+
79
+ async _fetchSingle({ entitlement, cache, force = false }) {
80
+ if (!force) {
81
+ const existing = this.cache.get(entitlement);
82
+
83
+ if (existing) {
84
+ return existing;
85
+ }
86
+ }
87
+
88
+ const data = await this.client.rest.get(Routes.entitlement(this.client.application.id, entitlement));
89
+ return this._add(data, cache);
90
+ }
91
+
92
+ async _fetchMany({ limit, guild, user, skus, excludeEnded, excludeDeleted, cache, before, after } = {}) {
60
93
  const query = makeURLSearchParams({
61
94
  limit,
62
95
  guild_id: guild && this.client.guilds.resolveId(guild),
63
96
  user_id: user && this.client.users.resolveId(user),
64
97
  sku_ids: skus?.map(sku => resolveSKUId(sku)).join(','),
65
98
  exclude_ended: excludeEnded,
99
+ exclude_deleted: excludeDeleted,
66
100
  before,
67
101
  after,
68
102
  });
69
103
 
70
104
  const entitlements = await this.client.rest.get(Routes.entitlements(this.client.application.id), { query });
105
+
71
106
  return entitlements.reduce(
72
107
  (coll, entitlement) => coll.set(entitlement.id, this._add(entitlement, cache)),
73
108
  new Collection(),
@@ -243,6 +243,36 @@ class ClientApplication extends Application {
243
243
  this.roleConnectionsVerificationURL ??= null;
244
244
  }
245
245
 
246
+ if ('event_webhooks_url' in data) {
247
+ /**
248
+ * This application's URL to receive event webhooks
249
+ * @type {?string}
250
+ */
251
+ this.eventWebhooksURL = data.event_webhooks_url;
252
+ } else {
253
+ this.eventWebhooksURL ??= null;
254
+ }
255
+
256
+ if ('event_webhooks_status' in data) {
257
+ /**
258
+ * This application's event webhooks status
259
+ * @type {?ApplicationWebhookEventStatus}
260
+ */
261
+ this.eventWebhooksStatus = data.event_webhooks_status;
262
+ } else {
263
+ this.eventWebhooksStatus ??= null;
264
+ }
265
+
266
+ if ('event_webhooks_types' in data) {
267
+ /**
268
+ * List of event webhooks types this application subscribes to
269
+ * @type {?ApplicationWebhookEventType[]}
270
+ */
271
+ this.eventWebhooksTypes = data.event_webhooks_types;
272
+ } else {
273
+ this.eventWebhooksTypes ??= null;
274
+ }
275
+
246
276
  /**
247
277
  * The owner of this OAuth application
248
278
  * @type {?(User|Team)}
@@ -284,6 +314,10 @@ class ClientApplication extends Application {
284
314
  * @property {?(BufferResolvable|Base64Resolvable)} [icon] The application's icon
285
315
  * @property {?(BufferResolvable|Base64Resolvable)} [coverImage] The application's cover image
286
316
  * @property {string} [interactionsEndpointURL] The application's interaction endpoint URL
317
+ * @property {string} [eventWebhooksURL] The application's event webhooks URL
318
+ * @property {ApplicationWebhookEventStatus.Enabled|ApplicationWebhookEventStatus.Disabled} [eventWebhooksStatus]
319
+ * The application's event webhooks status.
320
+ * @property {ApplicationWebhookEventType[]} [eventWebhooksTypes] The application's event webhooks types
287
321
  * @property {string[]} [tags] The application's tags
288
322
  */
289
323
 
@@ -301,6 +335,9 @@ class ClientApplication extends Application {
301
335
  icon,
302
336
  coverImage,
303
337
  interactionsEndpointURL,
338
+ eventWebhooksURL,
339
+ eventWebhooksStatus,
340
+ eventWebhooksTypes,
304
341
  tags,
305
342
  } = {}) {
306
343
  const data = await this.client.rest.patch(Routes.currentApplication(), {
@@ -313,6 +350,9 @@ class ClientApplication extends Application {
313
350
  icon: icon && (await resolveImage(icon)),
314
351
  cover_image: coverImage && (await resolveImage(coverImage)),
315
352
  interactions_endpoint_url: interactionsEndpointURL,
353
+ event_webhooks_url: eventWebhooksURL,
354
+ event_webhooks_status: eventWebhooksStatus,
355
+ event_webhooks_types: eventWebhooksTypes,
316
356
  tags,
317
357
  },
318
358
  });
@@ -5,7 +5,7 @@ const { ChannelFlags, ChannelType, PermissionFlagsBits, Routes } = require('disc
5
5
  const { BaseChannel } = require('./BaseChannel');
6
6
  const getThreadOnlyChannel = lazy(() => require('./ThreadOnlyChannel'));
7
7
  const TextBasedChannel = require('./interfaces/TextBasedChannel');
8
- const { DiscordjsError, DiscordjsRangeError, ErrorCodes } = require('../errors');
8
+ const { DiscordjsRangeError, ErrorCodes } = require('../errors');
9
9
  const GuildMessageManager = require('../managers/GuildMessageManager');
10
10
  const ThreadMemberManager = require('../managers/ThreadMemberManager');
11
11
  const ChannelFlagsBitField = require('../util/ChannelFlagsBitField');
@@ -31,6 +31,12 @@ class ThreadChannel extends BaseChannel {
31
31
  */
32
32
  this.guildId = guild?.id ?? data.guild_id;
33
33
 
34
+ /**
35
+ * The id of the member who created this thread
36
+ * @type {Snowflake}
37
+ */
38
+ this.ownerId = data.owner_id;
39
+
34
40
  /**
35
41
  * A manager of the messages sent to this thread
36
42
  * @type {GuildMessageManager}
@@ -121,16 +127,6 @@ class ThreadChannel extends BaseChannel {
121
127
 
122
128
  this._createdTimestamp ??= this.type === ChannelType.PrivateThread ? super.createdTimestamp : null;
123
129
 
124
- if ('owner_id' in data) {
125
- /**
126
- * The id of the member who created this thread
127
- * @type {?Snowflake}
128
- */
129
- this.ownerId = data.owner_id;
130
- } else {
131
- this.ownerId ??= null;
132
- }
133
-
134
130
  if ('last_message_id' in data) {
135
131
  /**
136
132
  * The last message id sent in this thread, if one was sent
@@ -300,10 +296,6 @@ class ThreadChannel extends BaseChannel {
300
296
  * @returns {Promise<ThreadMember>}
301
297
  */
302
298
  async fetchOwner(options) {
303
- if (!this.ownerId) {
304
- throw new DiscordjsError(ErrorCodes.FetchOwnerId, 'thread');
305
- }
306
-
307
299
  const member = await this.members._fetchSingle({ ...options, member: this.ownerId });
308
300
  return member;
309
301
  }
@@ -24,8 +24,8 @@ class InteractionResponses {
24
24
  /**
25
25
  * Options for deferring the reply to an {@link BaseInteraction}.
26
26
  * @typedef {Object} InteractionDeferReplyOptions
27
- * @property {MessageFlagsResolvable} [flags] Flags for the reply.
28
27
  * @property {boolean} [withResponse] Whether to return an {@link InteractionCallbackResponse} as the response
28
+ * @property {MessageFlagsResolvable} [flags] Flags for the reply.
29
29
  * <info>Only `MessageFlags.Ephemeral` can be set.</info>
30
30
  */
31
31
 
@@ -255,6 +255,16 @@
255
255
  * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/ApplicationRoleConnectionMetadataType}
256
256
  */
257
257
 
258
+ /**
259
+ * @external ApplicationWebhookEventStatus
260
+ * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/ApplicationWebhookEventStatus}
261
+ */
262
+
263
+ /**
264
+ * @external ApplicationWebhookEventType
265
+ * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/ApplicationWebhookEventType}
266
+ */
267
+
258
268
  /**
259
269
  * @external AttachmentFlags
260
270
  * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/AttachmentFlags}
@@ -167,6 +167,8 @@ import {
167
167
  SubscriptionStatus,
168
168
  GatewaySendPayload,
169
169
  GatewayDispatchPayload,
170
+ ApplicationWebhookEventStatus,
171
+ ApplicationWebhookEventType,
170
172
  RESTPostAPIInteractionCallbackWithResponseResult,
171
173
  RESTAPIInteractionCallbackObject,
172
174
  RESTAPIInteractionCallbackResourceObject,
@@ -999,7 +1001,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
999
1001
  public channels: ChannelManager;
1000
1002
  public get emojis(): BaseGuildEmojiManager;
1001
1003
  public guilds: GuildManager;
1002
- public lastPingTimestamp: number;
1004
+ public lastPingTimestamps: ReadonlyCollection<number, number>;
1003
1005
  public options: Omit<ClientOptions, 'intents'> & { intents: IntentsBitField };
1004
1006
  public get ping(): number | null;
1005
1007
  public get readyAt(): If<Ready, Date>;
@@ -1081,6 +1083,9 @@ export class ClientApplication extends Application {
1081
1083
  public owner: User | Team | null;
1082
1084
  public get partial(): boolean;
1083
1085
  public interactionsEndpointURL: string | null;
1086
+ public eventWebhooksURL: string | null;
1087
+ public eventWebhooksStatus: ApplicationWebhookEventStatus | null;
1088
+ public eventWebhooksTypes: ApplicationWebhookEventType[] | null;
1084
1089
  public roleConnectionsVerificationURL: string | null;
1085
1090
  public rpcOrigins: string[];
1086
1091
  public edit(options: ClientApplicationEditOptions): Promise<ClientApplication>;
@@ -3376,7 +3381,7 @@ export class ThreadChannel<ThreadOnly extends boolean = boolean> extends BaseCha
3376
3381
  public totalMessageSent: number | null;
3377
3382
  public members: ThreadMemberManager;
3378
3383
  public name: string;
3379
- public ownerId: Snowflake | null;
3384
+ public ownerId: Snowflake;
3380
3385
  public get parent(): If<ThreadOnly, ForumChannel | MediaChannel, TextChannel | AnnouncementChannel> | null;
3381
3386
  public parentId: Snowflake | null;
3382
3387
  public rateLimitPerUser: number | null;
@@ -4147,12 +4152,17 @@ export interface UserEntitlementCreateOptions {
4147
4152
  user: UserResolvable;
4148
4153
  }
4149
4154
 
4155
+ export interface FetchEntitlementOptions extends BaseFetchOptions {
4156
+ entitlement: EntitlementResolvable;
4157
+ }
4158
+
4150
4159
  export interface FetchEntitlementsOptions {
4151
4160
  limit?: number;
4152
4161
  guild?: GuildResolvable;
4153
4162
  user?: UserResolvable;
4154
4163
  skus?: readonly SKUResolvable[];
4155
4164
  excludeEnded?: boolean;
4165
+ excludeDeleted?: boolean;
4156
4166
  cache?: boolean;
4157
4167
  before?: Snowflake;
4158
4168
  after?: Snowflake;
@@ -4160,6 +4170,7 @@ export interface FetchEntitlementsOptions {
4160
4170
 
4161
4171
  export class EntitlementManager extends CachedManager<Snowflake, Entitlement, EntitlementResolvable> {
4162
4172
  private constructor(client: Client<true>, iterable: Iterable<APIEntitlement>);
4173
+ public fetch(options: EntitlementResolvable | FetchEntitlementOptions): Promise<Entitlement>;
4163
4174
  public fetch(options?: FetchEntitlementsOptions): Promise<Collection<Snowflake, Entitlement>>;
4164
4175
  public createTest(options: GuildEntitlementCreateOptions | UserEntitlementCreateOptions): Promise<Entitlement>;
4165
4176
  public deleteTest(entitlement: EntitlementResolvable): Promise<void>;
@@ -6966,6 +6977,9 @@ export interface ClientApplicationEditOptions {
6966
6977
  icon?: BufferResolvable | Base64Resolvable | null;
6967
6978
  coverImage?: BufferResolvable | Base64Resolvable | null;
6968
6979
  interactionsEndpointURL?: string;
6980
+ eventWebhooksURL?: string;
6981
+ eventWebhooksStatus?: ApplicationWebhookEventStatus.Enabled | ApplicationWebhookEventStatus.Disabled;
6982
+ eventWebhooksTypes?: readonly ApplicationWebhookEventType[];
6969
6983
  tags?: readonly string[];
6970
6984
  }
6971
6985
 
@@ -167,6 +167,8 @@ import {
167
167
  SubscriptionStatus,
168
168
  GatewaySendPayload,
169
169
  GatewayDispatchPayload,
170
+ ApplicationWebhookEventStatus,
171
+ ApplicationWebhookEventType,
170
172
  RESTPostAPIInteractionCallbackWithResponseResult,
171
173
  RESTAPIInteractionCallbackObject,
172
174
  RESTAPIInteractionCallbackResourceObject,
@@ -999,7 +1001,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
999
1001
  public channels: ChannelManager;
1000
1002
  public get emojis(): BaseGuildEmojiManager;
1001
1003
  public guilds: GuildManager;
1002
- public lastPingTimestamp: number;
1004
+ public lastPingTimestamps: ReadonlyCollection<number, number>;
1003
1005
  public options: Omit<ClientOptions, 'intents'> & { intents: IntentsBitField };
1004
1006
  public get ping(): number | null;
1005
1007
  public get readyAt(): If<Ready, Date>;
@@ -1081,6 +1083,9 @@ export class ClientApplication extends Application {
1081
1083
  public owner: User | Team | null;
1082
1084
  public get partial(): boolean;
1083
1085
  public interactionsEndpointURL: string | null;
1086
+ public eventWebhooksURL: string | null;
1087
+ public eventWebhooksStatus: ApplicationWebhookEventStatus | null;
1088
+ public eventWebhooksTypes: ApplicationWebhookEventType[] | null;
1084
1089
  public roleConnectionsVerificationURL: string | null;
1085
1090
  public rpcOrigins: string[];
1086
1091
  public edit(options: ClientApplicationEditOptions): Promise<ClientApplication>;
@@ -3376,7 +3381,7 @@ export class ThreadChannel<ThreadOnly extends boolean = boolean> extends BaseCha
3376
3381
  public totalMessageSent: number | null;
3377
3382
  public members: ThreadMemberManager;
3378
3383
  public name: string;
3379
- public ownerId: Snowflake | null;
3384
+ public ownerId: Snowflake;
3380
3385
  public get parent(): If<ThreadOnly, ForumChannel | MediaChannel, TextChannel | AnnouncementChannel> | null;
3381
3386
  public parentId: Snowflake | null;
3382
3387
  public rateLimitPerUser: number | null;
@@ -4147,12 +4152,17 @@ export interface UserEntitlementCreateOptions {
4147
4152
  user: UserResolvable;
4148
4153
  }
4149
4154
 
4155
+ export interface FetchEntitlementOptions extends BaseFetchOptions {
4156
+ entitlement: EntitlementResolvable;
4157
+ }
4158
+
4150
4159
  export interface FetchEntitlementsOptions {
4151
4160
  limit?: number;
4152
4161
  guild?: GuildResolvable;
4153
4162
  user?: UserResolvable;
4154
4163
  skus?: readonly SKUResolvable[];
4155
4164
  excludeEnded?: boolean;
4165
+ excludeDeleted?: boolean;
4156
4166
  cache?: boolean;
4157
4167
  before?: Snowflake;
4158
4168
  after?: Snowflake;
@@ -4160,6 +4170,7 @@ export interface FetchEntitlementsOptions {
4160
4170
 
4161
4171
  export class EntitlementManager extends CachedManager<Snowflake, Entitlement, EntitlementResolvable> {
4162
4172
  private constructor(client: Client<true>, iterable: Iterable<APIEntitlement>);
4173
+ public fetch(options: EntitlementResolvable | FetchEntitlementOptions): Promise<Entitlement>;
4163
4174
  public fetch(options?: FetchEntitlementsOptions): Promise<Collection<Snowflake, Entitlement>>;
4164
4175
  public createTest(options: GuildEntitlementCreateOptions | UserEntitlementCreateOptions): Promise<Entitlement>;
4165
4176
  public deleteTest(entitlement: EntitlementResolvable): Promise<void>;
@@ -6966,6 +6977,9 @@ export interface ClientApplicationEditOptions {
6966
6977
  icon?: BufferResolvable | Base64Resolvable | null;
6967
6978
  coverImage?: BufferResolvable | Base64Resolvable | null;
6968
6979
  interactionsEndpointURL?: string;
6980
+ eventWebhooksURL?: string;
6981
+ eventWebhooksStatus?: ApplicationWebhookEventStatus.Enabled | ApplicationWebhookEventStatus.Disabled;
6982
+ eventWebhooksTypes?: readonly ApplicationWebhookEventType[];
6969
6983
  tags?: readonly string[];
6970
6984
  }
6971
6985
 
@@ -2002,8 +2002,6 @@ client.on('interactionCreate', async interaction => {
2002
2002
  );
2003
2003
  expectType<MediaChannel>(interaction.options.getChannel('test', true, [ChannelType.GuildMedia]));
2004
2004
  } else {
2005
- // @ts-expect-error
2006
- consumeCachedCommand(interaction);
2007
2005
  expectType<ChatInputCommandInteraction>(interaction);
2008
2006
  expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ withResponse: true }));
2009
2007
  expectType<APIInteractionDataResolvedGuildMember | GuildMember | null>(interaction.options.getMember('test'));