discord.js 14.19.0 → 14.19.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/package.json +1 -1
- package/src/client/websocket/WebSocketManager.js +9 -6
- package/src/managers/GuildSoundboardSoundManager.js +2 -2
- package/src/structures/Guild.js +7 -0
- package/src/structures/GuildAuditLogsEntry.js +0 -1
- package/src/structures/MessagePayload.js +2 -1
- package/src/structures/SoundboardSound.js +4 -4
- package/src/structures/UnfurledMediaItem.js +8 -0
- package/src/structures/Webhook.js +11 -4
- package/src/util/Components.js +21 -10
- package/typings/index.d.mts +9 -1
- package/typings/index.d.ts +9 -1
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": "14.19.
|
|
4
|
+
"version": "14.19.2",
|
|
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",
|
|
@@ -36,10 +36,13 @@ const BeforeReadyWhitelist = [
|
|
|
36
36
|
|
|
37
37
|
const WaitingForGuildEvents = [GatewayDispatchEvents.GuildCreate, GatewayDispatchEvents.GuildDelete];
|
|
38
38
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
GatewayCloseCodes.
|
|
42
|
-
GatewayCloseCodes.
|
|
39
|
+
const UNRECOVERABLE_CLOSE_CODES = [
|
|
40
|
+
GatewayCloseCodes.AuthenticationFailed,
|
|
41
|
+
GatewayCloseCodes.InvalidShard,
|
|
42
|
+
GatewayCloseCodes.ShardingRequired,
|
|
43
|
+
GatewayCloseCodes.InvalidAPIVersion,
|
|
44
|
+
GatewayCloseCodes.InvalidIntents,
|
|
45
|
+
GatewayCloseCodes.DisallowedIntents,
|
|
43
46
|
];
|
|
44
47
|
|
|
45
48
|
const reasonIsDeprecated = 'the reason property is deprecated, use the code property to determine the reason';
|
|
@@ -242,7 +245,7 @@ class WebSocketManager extends EventEmitter {
|
|
|
242
245
|
this._ws.on(WSWebSocketShardEvents.Closed, ({ code, shardId }) => {
|
|
243
246
|
const shard = this.shards.get(shardId);
|
|
244
247
|
shard.emit(WebSocketShardEvents.Close, { code, reason: reasonIsDeprecated, wasClean: true });
|
|
245
|
-
if (
|
|
248
|
+
if (UNRECOVERABLE_CLOSE_CODES.includes(code)) {
|
|
246
249
|
shard.status = Status.Disconnected;
|
|
247
250
|
/**
|
|
248
251
|
* Emitted when a shard's WebSocket disconnects and will no longer reconnect.
|
|
@@ -251,7 +254,7 @@ class WebSocketManager extends EventEmitter {
|
|
|
251
254
|
* @param {number} id The shard id that disconnected
|
|
252
255
|
*/
|
|
253
256
|
this.client.emit(Events.ShardDisconnect, { code, reason: reasonIsDeprecated, wasClean: true }, shardId);
|
|
254
|
-
this.debug([`Shard not
|
|
257
|
+
this.debug([`Shard not recoverable: ${code} (${GatewayCloseCodes[code] ?? CloseCodes[code]})`], shardId);
|
|
255
258
|
return;
|
|
256
259
|
}
|
|
257
260
|
|
|
@@ -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
|
|
@@ -190,7 +190,7 @@ class GuildSoundboardSoundManager extends CachedManager {
|
|
|
190
190
|
if (!options) return this._fetchMany();
|
|
191
191
|
const { cache, force, soundboardSound } = options;
|
|
192
192
|
const resolvedSoundboardSound = this.resolveId(soundboardSound ?? options);
|
|
193
|
-
if (resolvedSoundboardSound) return this._fetchSingle({ cache, force, soundboardSound });
|
|
193
|
+
if (resolvedSoundboardSound) return this._fetchSingle({ cache, force, soundboardSound: resolvedSoundboardSound });
|
|
194
194
|
return this._fetchMany({ cache });
|
|
195
195
|
}
|
|
196
196
|
|
package/src/structures/Guild.js
CHANGED
|
@@ -499,6 +499,13 @@ class Guild extends AnonymousGuild {
|
|
|
499
499
|
} else {
|
|
500
500
|
this.incidentsData ??= null;
|
|
501
501
|
}
|
|
502
|
+
|
|
503
|
+
if (data.soundboard_sounds) {
|
|
504
|
+
this.soundboardSounds.cache.clear();
|
|
505
|
+
for (const soundboardSound of data.soundboard_sounds) {
|
|
506
|
+
this.soundboardSounds._add(soundboardSound);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
502
509
|
}
|
|
503
510
|
|
|
504
511
|
/**
|
|
@@ -487,7 +487,6 @@ class GuildAuditLogsEntry {
|
|
|
487
487
|
AuditLogEvent.ThreadUpdate,
|
|
488
488
|
AuditLogEvent.SoundboardSoundUpdate,
|
|
489
489
|
AuditLogEvent.ApplicationCommandPermissionUpdate,
|
|
490
|
-
AuditLogEvent.SoundboardSoundUpdate,
|
|
491
490
|
AuditLogEvent.AutoModerationRuleUpdate,
|
|
492
491
|
AuditLogEvent.AutoModerationBlockMessage,
|
|
493
492
|
AuditLogEvent.AutoModerationFlagToChannel,
|
|
@@ -248,7 +248,8 @@ class MessagePayload {
|
|
|
248
248
|
components,
|
|
249
249
|
username,
|
|
250
250
|
avatar_url: avatarURL,
|
|
251
|
-
allowed_mentions:
|
|
251
|
+
allowed_mentions:
|
|
252
|
+
this.isMessage && this.target.author.id !== this.target.client.user.id ? undefined : allowedMentions,
|
|
252
253
|
flags,
|
|
253
254
|
message_reference,
|
|
254
255
|
attachments: this.options.attachments,
|
|
@@ -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.
|
|
185
|
-
this.
|
|
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.
|
|
197
|
-
this.
|
|
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
|
);
|
|
@@ -20,6 +20,14 @@ class UnfurledMediaItem {
|
|
|
20
20
|
get url() {
|
|
21
21
|
return this.data.url;
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns the API-compatible JSON for this media item
|
|
26
|
+
* @returns {APIUnfurledMediaItem}
|
|
27
|
+
*/
|
|
28
|
+
toJSON() {
|
|
29
|
+
return { ...this.data };
|
|
30
|
+
}
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
module.exports = UnfurledMediaItem;
|
|
@@ -137,6 +137,8 @@ class Webhook {
|
|
|
137
137
|
* @property {string} [threadName] Name of the thread to create (only available if the webhook is in a forum channel)
|
|
138
138
|
* @property {Snowflake[]} [appliedTags]
|
|
139
139
|
* The tags to apply to the created thread (only available if the webhook is in a forum channel)
|
|
140
|
+
* @property {boolean} [withComponents] Whether to allow sending non-interactive components in the message.
|
|
141
|
+
* <info>For application-owned webhooks, this property is ignored</info>
|
|
140
142
|
*/
|
|
141
143
|
|
|
142
144
|
/**
|
|
@@ -219,7 +221,7 @@ class Webhook {
|
|
|
219
221
|
const query = makeURLSearchParams({
|
|
220
222
|
wait: true,
|
|
221
223
|
thread_id: messagePayload.options.threadId,
|
|
222
|
-
with_components:
|
|
224
|
+
with_components: messagePayload.options.withComponents,
|
|
223
225
|
});
|
|
224
226
|
|
|
225
227
|
const d = await this.client.rest.post(Routes.webhook(this.id, this.token), {
|
|
@@ -300,6 +302,8 @@ class Webhook {
|
|
|
300
302
|
* @property {boolean} [cache=true] Whether to cache the message.
|
|
301
303
|
* @property {Snowflake} [threadId] The id of the thread this message belongs to.
|
|
302
304
|
* <info>For interaction webhooks, this property is ignored</info>
|
|
305
|
+
* @property {boolean} [withComponents] Whether to allow sending non-interactive components in the message.
|
|
306
|
+
* <info>For application-owned webhooks, this property is ignored</info>
|
|
303
307
|
*/
|
|
304
308
|
|
|
305
309
|
/**
|
|
@@ -339,14 +343,17 @@ class Webhook {
|
|
|
339
343
|
|
|
340
344
|
const { body, files } = await messagePayload.resolveBody().resolveFiles();
|
|
341
345
|
|
|
346
|
+
const query = makeURLSearchParams({
|
|
347
|
+
thread_id: messagePayload.options.threadId,
|
|
348
|
+
with_components: messagePayload.options.withComponents,
|
|
349
|
+
});
|
|
350
|
+
|
|
342
351
|
const d = await this.client.rest.patch(
|
|
343
352
|
Routes.webhookMessage(this.id, this.token, typeof message === 'string' ? message : message.id),
|
|
344
353
|
{
|
|
345
354
|
body,
|
|
346
355
|
files,
|
|
347
|
-
query
|
|
348
|
-
? makeURLSearchParams({ thread_id: messagePayload.options.threadId })
|
|
349
|
-
: undefined,
|
|
356
|
+
query,
|
|
350
357
|
auth: false,
|
|
351
358
|
},
|
|
352
359
|
);
|
package/src/util/Components.js
CHANGED
|
@@ -214,25 +214,36 @@ function createComponentBuilder(data) {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Extracts all interactive components from the component tree
|
|
219
|
+
* @param {Component|APIMessageComponent} component The component to find all interactive components in
|
|
220
|
+
* @returns {Array<Component|APIMessageComponent>}
|
|
221
|
+
* @ignore
|
|
222
|
+
*/
|
|
223
|
+
function extractInteractiveComponents(component) {
|
|
224
|
+
switch (component.type) {
|
|
225
|
+
case ComponentType.ActionRow:
|
|
226
|
+
return component.components;
|
|
227
|
+
case ComponentType.Section:
|
|
228
|
+
return [...component.components, component.accessory];
|
|
229
|
+
case ComponentType.Container:
|
|
230
|
+
return component.components.flatMap(extractInteractiveComponents);
|
|
231
|
+
default:
|
|
232
|
+
return [component];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
217
236
|
/**
|
|
218
237
|
* Finds a component by customId in nested components
|
|
219
238
|
* @param {Array<Component|APIMessageComponent>} components The components to search in
|
|
220
239
|
* @param {string} customId The customId to search for
|
|
221
240
|
* @returns {Component|APIMessageComponent}
|
|
241
|
+
* @ignore
|
|
222
242
|
*/
|
|
223
243
|
function findComponentByCustomId(components, customId) {
|
|
224
244
|
return (
|
|
225
245
|
components
|
|
226
|
-
.flatMap(
|
|
227
|
-
switch (component.type) {
|
|
228
|
-
case ComponentType.ActionRow:
|
|
229
|
-
return component.components;
|
|
230
|
-
case ComponentType.Section:
|
|
231
|
-
return [...component.components, component.accessory];
|
|
232
|
-
default:
|
|
233
|
-
return [component];
|
|
234
|
-
}
|
|
235
|
-
})
|
|
246
|
+
.flatMap(extractInteractiveComponents)
|
|
236
247
|
.find(component => (component.customId ?? component.custom_id) === customId) ?? null
|
|
237
248
|
);
|
|
238
249
|
}
|
package/typings/index.d.mts
CHANGED
|
@@ -4857,6 +4857,7 @@ export interface GuildSoundboardSoundEditOptions {
|
|
|
4857
4857
|
volume?: number | null;
|
|
4858
4858
|
emojiId?: Snowflake | null;
|
|
4859
4859
|
emojiName?: string | null;
|
|
4860
|
+
reason?: string;
|
|
4860
4861
|
}
|
|
4861
4862
|
|
|
4862
4863
|
export interface FetchGuildSoundboardSoundOptions extends BaseFetchOptions {
|
|
@@ -7043,7 +7044,12 @@ export interface MessageEditAttachmentData {
|
|
|
7043
7044
|
export interface MessageEditOptions extends Omit<BaseMessageOptions, 'content'> {
|
|
7044
7045
|
content?: string | null;
|
|
7045
7046
|
attachments?: readonly (Attachment | MessageEditAttachmentData)[];
|
|
7046
|
-
flags?:
|
|
7047
|
+
flags?:
|
|
7048
|
+
| BitFieldResolvable<
|
|
7049
|
+
Extract<MessageFlagsString, 'SuppressEmbeds' | 'IsComponentsV2'>,
|
|
7050
|
+
MessageFlags.SuppressEmbeds | MessageFlags.IsComponentsV2
|
|
7051
|
+
>
|
|
7052
|
+
| undefined;
|
|
7047
7053
|
}
|
|
7048
7054
|
|
|
7049
7055
|
export type MessageReactionResolvable = MessageReaction | Snowflake | string;
|
|
@@ -7559,6 +7565,7 @@ export interface WebhookEditOptions {
|
|
|
7559
7565
|
|
|
7560
7566
|
export interface WebhookMessageEditOptions extends MessageEditOptions {
|
|
7561
7567
|
threadId?: Snowflake;
|
|
7568
|
+
withComponents?: boolean;
|
|
7562
7569
|
}
|
|
7563
7570
|
|
|
7564
7571
|
export interface InteractionEditReplyOptions
|
|
@@ -7578,6 +7585,7 @@ export interface WebhookMessageCreateOptions
|
|
|
7578
7585
|
threadId?: Snowflake;
|
|
7579
7586
|
threadName?: string;
|
|
7580
7587
|
appliedTags?: readonly Snowflake[];
|
|
7588
|
+
withComponents?: boolean;
|
|
7581
7589
|
}
|
|
7582
7590
|
|
|
7583
7591
|
export interface WebSocketOptions {
|
package/typings/index.d.ts
CHANGED
|
@@ -4857,6 +4857,7 @@ export interface GuildSoundboardSoundEditOptions {
|
|
|
4857
4857
|
volume?: number | null;
|
|
4858
4858
|
emojiId?: Snowflake | null;
|
|
4859
4859
|
emojiName?: string | null;
|
|
4860
|
+
reason?: string;
|
|
4860
4861
|
}
|
|
4861
4862
|
|
|
4862
4863
|
export interface FetchGuildSoundboardSoundOptions extends BaseFetchOptions {
|
|
@@ -7043,7 +7044,12 @@ export interface MessageEditAttachmentData {
|
|
|
7043
7044
|
export interface MessageEditOptions extends Omit<BaseMessageOptions, 'content'> {
|
|
7044
7045
|
content?: string | null;
|
|
7045
7046
|
attachments?: readonly (Attachment | MessageEditAttachmentData)[];
|
|
7046
|
-
flags?:
|
|
7047
|
+
flags?:
|
|
7048
|
+
| BitFieldResolvable<
|
|
7049
|
+
Extract<MessageFlagsString, 'SuppressEmbeds' | 'IsComponentsV2'>,
|
|
7050
|
+
MessageFlags.SuppressEmbeds | MessageFlags.IsComponentsV2
|
|
7051
|
+
>
|
|
7052
|
+
| undefined;
|
|
7047
7053
|
}
|
|
7048
7054
|
|
|
7049
7055
|
export type MessageReactionResolvable = MessageReaction | Snowflake | string;
|
|
@@ -7559,6 +7565,7 @@ export interface WebhookEditOptions {
|
|
|
7559
7565
|
|
|
7560
7566
|
export interface WebhookMessageEditOptions extends MessageEditOptions {
|
|
7561
7567
|
threadId?: Snowflake;
|
|
7568
|
+
withComponents?: boolean;
|
|
7562
7569
|
}
|
|
7563
7570
|
|
|
7564
7571
|
export interface InteractionEditReplyOptions
|
|
@@ -7578,6 +7585,7 @@ export interface WebhookMessageCreateOptions
|
|
|
7578
7585
|
threadId?: Snowflake;
|
|
7579
7586
|
threadName?: string;
|
|
7580
7587
|
appliedTags?: readonly Snowflake[];
|
|
7588
|
+
withComponents?: boolean;
|
|
7581
7589
|
}
|
|
7582
7590
|
|
|
7583
7591
|
export interface WebSocketOptions {
|