Compare commits

...

24 Commits

Author SHA1 Message Date
Vlad Frangu
8ab30cdefa chore(core): release @discordjs/core@2.2.0 2025-06-26 01:26:48 +03:00
Danial Raza
c2a43b685e types(ClientEventTypes): add missing guildSoundboardSoundsUpdate (#10928) 2025-06-25 16:22:07 +01:00
Jiralite
507b696792 fix(ClientUser): Remove token assignment (#10953)
fix(ClientUser): remove token assignment
2025-06-25 16:15:35 +01:00
Jiralite
15f7571243 feat(GuildMember): add avatarDecorationData (#10942)
Co-Authored-By: Danial Raza <danialrazafb@gmail.com>
2025-06-25 12:31:43 +01:00
Almeida
3fa429c7df feat(ClientApplication): add approximateUserAuthorizationCount (#10933)
Co-authored-by: Danial Raza <danialrazafb@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2025-06-25 12:22:36 +01:00
Jiralite
7713627fd1 feat(webhook): Support with_components (#10945)
feat: support `with_components`
2025-06-22 10:48:47 +01:00
Vlad Frangu
6a5c0fb32d chore(discord.js): release discord.js@14.20.0 2025-06-16 15:41:03 +03:00
Vlad Frangu
eb5acd1e30 chore(discord.js): bump ws 2025-06-16 15:39:20 +03:00
Vlad Frangu
127021d5ab chore(core): release @discordjs/core@2.1.1 2025-06-16 15:30:25 +03:00
Vlad Frangu
0943bc2efb chore(ws): release @discordjs/ws@2.0.3 2025-06-16 15:29:02 +03:00
Vlad Frangu
a1c83c17d6 chore(rest): release @discordjs/rest@2.5.1 2025-06-16 14:55:15 +03:00
Qjuh
c0eae344c2 feat: backport entrypoint command (#10908) 2025-05-27 21:50:26 +02:00
Qjuh
f2f757ce52 fix: use resolvePartialEmoji on MessagePayload#options#components (#10910)
fix: use resolvePartialEmoji on MessagePayload#components again
2025-05-25 13:35:28 +02:00
Jiralite
65cfa3ffd3 build: Update Undici to 6.21.3 (#10906)
build: update undici
2025-05-20 11:52:49 +01:00
Jiralite
ee2eb7349f fix(ChannelManager): Remove threads from cache upon deletion (#10883)
* fix(ChannelManager): remove threads from cache upon deletion

* refactor: loop over thread ids

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2025-05-09 14:09:35 +01:00
Jiralite
2d19163d76 perf(Components): Hash table (#10893)
perf(Components): hash table
2025-05-09 08:43:04 +01:00
Jiralite
9bca4af5fd fix(PartialGroupDMChannel): Prevent undefined values (#10889)
fix(PartialGroupDMChannel): prevent `undefined` values

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2025-05-07 19:09:26 +01:00
Almeida
fe5e344adc build: exclude type tests from pack (#10886)
* build: exclude type tests from pack

* fix: requested changes

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2025-05-07 17:36:47 +01:00
Jiralite
c8f6066d6a refactor(Client): Remove with_expiration query parameter (#10800)
refactor(Client): remove `with_expiration`

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2025-05-06 15:25:32 +01:00
Almeida
7e21a9474e feat(BaseInteraction): add attachmentSizeLimit (#10830)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2025-05-05 03:54:12 +01:00
Jiralite
d0a535ea6a fix(guild): fix incorrectly-detected deprecated overload 2025-05-04 14:19:24 +01:00
Vlad Frangu
8124fc68be chore(discord.js): release discord.js@14.19.3 2025-05-03 01:08:35 +03:00
Vlad Frangu
dbd5354056 chore: bump builders 2025-05-03 01:07:23 +03:00
Qjuh
2ebb5cbd53 fix: regression in allowedMentions when replying (#10866)
* fix: regression in allowedMentions

* fix: lint

* fix: jsdoc

* tests: added a manual regression test

* fix: lint

* fix: tests

* fix: tests

* fix: typo

* fix: typings test

* chore: bumo zlib-sync to not crash on mac
2025-05-02 12:48:57 +02:00
34 changed files with 615 additions and 142 deletions

View File

@@ -2,6 +2,18 @@
All notable changes to this project will be documented in this file.
# [@discordjs/core@2.2.0](https://github.com/discordjs/discord.js/compare/@discordjs/core@2.1.1...@discordjs/core@2.2.0) - (2025-06-25)
## Features
- **webhook:** Support `with_components` (#10945) ([7713627](https://github.com/discordjs/discord.js/commit/7713627fd18599a6187b325e1e4bc9a17cf23e21))
# [@discordjs/core@2.1.1](https://github.com/discordjs/discord.js/compare/@discordjs/core@2.1.0...@discordjs/core@2.1.1) - (2025-06-16)
## Bug Fixes
- **guild:** Fix incorrectly-detected deprecated overload ([d0a535e](https://github.com/discordjs/discord.js/commit/d0a535ea6a66861276691a51547adfb2bcef0384))
# [@discordjs/core@2.1.0](https://github.com/discordjs/discord.js/compare/@discordjs/core@2.0.1...@discordjs/core@2.1.0) - (2025-04-25)
## Features

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/core",
"version": "2.1.0",
"version": "2.2.0",
"description": "A thinly abstracted wrapper around the rest API, and gateway.",
"scripts": {
"test": "vitest run",

View File

@@ -115,7 +115,7 @@ export class GuildsAPI {
* @param options - The options for fetching the guild
* @deprecated Use the overload with a query instead.
*/
public async get(guildId: Snowflake, { signal }?: Pick<RequestData, 'signal'>): Promise<RESTGetAPIGuildResult>;
public async get(guildId: Snowflake, { signal }: Pick<RequestData, 'signal'>): Promise<RESTGetAPIGuildResult>;
/**
* Fetches a guild

View File

@@ -9,6 +9,7 @@ import {
type RESTPatchAPIWebhookJSONBody,
type RESTPatchAPIWebhookResult,
type RESTPatchAPIWebhookWithTokenMessageJSONBody,
type RESTPatchAPIWebhookWithTokenMessageQuery,
type RESTPatchAPIWebhookWithTokenMessageResult,
type RESTPostAPIWebhookWithTokenGitHubQuery,
type RESTPostAPIWebhookWithTokenJSONBody,
@@ -127,13 +128,14 @@ export class WebhooksAPI {
{
wait,
thread_id,
with_components,
files,
...body
}: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.webhook(id, token), {
query: makeURLSearchParams({ wait, thread_id }),
query: makeURLSearchParams({ wait, thread_id, with_components }),
files,
body,
auth: false,
@@ -232,13 +234,14 @@ export class WebhooksAPI {
messageId: Snowflake,
{
thread_id,
with_components,
files,
...body
}: RESTPatchAPIWebhookWithTokenMessageJSONBody & { files?: RawFile[]; thread_id?: string },
}: RESTPatchAPIWebhookWithTokenMessageJSONBody & RESTPatchAPIWebhookWithTokenMessageQuery & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.patch(Routes.webhookMessage(id, token, messageId), {
query: makeURLSearchParams({ thread_id }),
query: makeURLSearchParams({ thread_id, with_components }),
auth: false,
body,
signal,

View File

@@ -1,5 +1,5 @@
{
"$schema": "https://json.schemastore.org/lintstagedrc.schema.json",
"*": "prettier --ignore-unknown --write",
"{src/**,test/**,typings/**,scripts/**}.{mjs,js,ts}": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint --ext mjs,js,ts --fix"
"{src/**,typings/**,scripts/**}.{mjs,js,ts}": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint --ext mjs,js,ts --fix"
}

View File

@@ -2,6 +2,33 @@
All notable changes to this project will be documented in this file.
# [14.20.0](https://github.com/discordjs/discord.js/compare/14.19.3...14.20.0) - (2025-06-16)
## Bug Fixes
- Use resolvePartialEmoji on MessagePayload#options#components (#10910) ([f2f757c](https://github.com/discordjs/discord.js/commit/f2f757ce52b76d5e571f47f9bf1c5188627b80d5))
- **ChannelManager:** Remove threads from cache upon deletion (#10883) ([ee2eb73](https://github.com/discordjs/discord.js/commit/ee2eb7349f2467451880baaea54e02074916015f))
- **PartialGroupDMChannel:** Prevent `undefined` values (#10889) ([9bca4af](https://github.com/discordjs/discord.js/commit/9bca4af5fdb78fae7b970498db7f93df31f55ef9))
## Features
- Backport entrypoint command (#10908) ([c0eae34](https://github.com/discordjs/discord.js/commit/c0eae344c2ed43fa67be9fda8e3d3e479693d2d1))
- **BaseInteraction:** Add `attachmentSizeLimit` (#10830) ([7e21a94](https://github.com/discordjs/discord.js/commit/7e21a9474e532c5b22c6e0600c446fca47352617))
## Performance
- **Components:** Hash table (#10893) ([2d19163](https://github.com/discordjs/discord.js/commit/2d19163d764705667691430e438499fd330ffb65))
## Refactor
- **Client:** Remove `with_expiration` query parameter (#10800) ([c8f6066](https://github.com/discordjs/discord.js/commit/c8f6066d6a0a1fc6ac23a49d66604d95b588af3e))
# [14.19.3](https://github.com/discordjs/discord.js/compare/14.19.2...14.19.3) - (2025-05-02)
## Bug Fixes
- Regression in allowedMentions when replying (#10866) ([2ebb5cb](https://github.com/discordjs/discord.js/commit/2ebb5cbd53d869a52cba4549e7acc417963741cd))
# [14.19.2](https://github.com/discordjs/discord.js/compare/14.19.1...14.19.2) - (2025-04-28)
## Bug Fixes

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "discord.js",
"version": "14.19.2",
"version": "14.20.0",
"description": "A powerful library for interacting with the Discord API",
"scripts": {
"test": "pnpm run docs:test && pnpm run test:typescript",
@@ -36,7 +36,8 @@
},
"files": [
"src",
"typings"
"typings/*.d.ts",
"typings/*.d.mts"
],
"contributors": [
"Crawl <icrawltogo@gmail.com>",
@@ -65,19 +66,19 @@
"homepage": "https://discord.js.org",
"funding": "https://github.com/discordjs/discord.js?sponsor",
"dependencies": {
"@discordjs/builders": "^1.11.1",
"@discordjs/builders": "^1.11.2",
"@discordjs/collection": "1.5.3",
"@discordjs/formatters": "^0.6.1",
"@discordjs/rest": "workspace:^",
"@discordjs/util": "workspace:^",
"@discordjs/ws": "^1.2.2",
"@discordjs/ws": "^1.2.3",
"@sapphire/snowflake": "3.5.3",
"discord-api-types": "^0.38.1",
"fast-deep-equal": "3.1.3",
"lodash.snakecase": "4.1.1",
"magic-bytes.js": "^1.10.0",
"tslib": "^2.6.3",
"undici": "6.21.1"
"undici": "6.21.3"
},
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",

View File

@@ -277,7 +277,6 @@ class Client extends BaseClient {
const code = resolveInviteCode(invite);
const query = makeURLSearchParams({
with_counts: true,
with_expiration: true,
guild_scheduled_event_id: options?.guildScheduledEventId,
});
const data = await this.rest.get(Routes.invite(code), { query });

View File

@@ -9,6 +9,7 @@ const ChatInputCommandInteraction = require('../../structures/ChatInputCommandIn
const MentionableSelectMenuInteraction = require('../../structures/MentionableSelectMenuInteraction');
const MessageContextMenuCommandInteraction = require('../../structures/MessageContextMenuCommandInteraction');
const ModalSubmitInteraction = require('../../structures/ModalSubmitInteraction');
const PrimaryEntryPointCommandInteraction = require('../../structures/PrimaryEntryPointCommandInteraction');
const RoleSelectMenuInteraction = require('../../structures/RoleSelectMenuInteraction');
const StringSelectMenuInteraction = require('../../structures/StringSelectMenuInteraction');
const UserContextMenuCommandInteraction = require('../../structures/UserContextMenuCommandInteraction');
@@ -38,6 +39,9 @@ class InteractionCreateAction extends Action {
if (channel && !channel.isTextBased()) return;
InteractionClass = MessageContextMenuCommandInteraction;
break;
case ApplicationCommandType.PrimaryEntryPoint:
InteractionClass = PrimaryEntryPointCommandInteraction;
break;
default:
client.emit(
Events.Debug,

View File

@@ -180,6 +180,7 @@ exports.PartialGroupDMChannel = require('./structures/PartialGroupDMChannel');
exports.PermissionOverwrites = require('./structures/PermissionOverwrites');
exports.Poll = require('./structures/Poll').Poll;
exports.PollAnswer = require('./structures/PollAnswer').PollAnswer;
exports.PrimaryEntryPointCommandInteraction = require('./structures/PrimaryEntryPointCommandInteraction');
exports.Presence = require('./structures/Presence').Presence;
exports.ReactionCollector = require('./structures/ReactionCollector');
exports.ReactionEmoji = require('./structures/ReactionEmoji');

View File

@@ -261,6 +261,7 @@ class ApplicationCommandManager extends CachedManager {
dm_permission: command.dmPermission ?? command.dm_permission,
integration_types: command.integrationTypes ?? command.integration_types,
contexts: command.contexts,
handler: command.handler,
};
}
}

View File

@@ -69,6 +69,13 @@ class ChannelManager extends CachedManager {
channel?.parent?.threads?.cache.delete(id);
this.cache.delete(id);
if (channel?.threads) {
for (const threadId of channel.threads.cache.keys()) {
this.cache.delete(threadId);
channel.guild?.channels.cache.delete(threadId);
}
}
}
/**

View File

@@ -174,6 +174,18 @@ class ApplicationCommand extends Base {
this.contexts ??= null;
}
if ('handler' in data) {
/**
* Determines whether the interaction is handled by the app's interactions handler or by Discord.
* <info>Only available for {@link ApplicationCommandType.PrimaryEntryPoint} commands on
* applications with the {@link ApplicationFlags.Embedded} flag (i.e, those that have an Activity)</info>
* @type {?EntryPointCommandHandlerType}
*/
this.handler = data.handler;
} else {
this.handler ??= null;
}
if ('version' in data) {
/**
* Autoincrementing version identifier updated during substantial record changes
@@ -216,15 +228,20 @@ class ApplicationCommand extends Base {
* @property {string} name The name of the command, must be in all lowercase if type is
* {@link ApplicationCommandType.ChatInput}
* @property {Object<Locale, string>} [nameLocalizations] The localizations for the command name
* @property {string} description The description of the command, if type is {@link ApplicationCommandType.ChatInput}
* @property {string} description The description of the command,
* if type is {@link ApplicationCommandType.ChatInput} or {@link ApplicationCommandType.PrimaryEntryPoint}
* @property {boolean} [nsfw] Whether the command is age-restricted
* @property {Object<Locale, string>} [descriptionLocalizations] The localizations for the command description,
* if type is {@link ApplicationCommandType.ChatInput}
* if type is {@link ApplicationCommandType.ChatInput} or {@link ApplicationCommandType.PrimaryEntryPoint}
* @property {ApplicationCommandType} [type=ApplicationCommandType.ChatInput] The type of the command
* @property {ApplicationCommandOptionData[]} [options] Options for the command
* @property {?PermissionResolvable} [defaultMemberPermissions] The bitfield used to determine the default permissions
* a member needs in order to run the command
* @property {boolean} [dmPermission] Whether the command is enabled in DMs
* @property {ApplicationIntegrationType[]} [integrationTypes] Installation contexts where the command is available
* @property {InteractionContextType[]} [contexts] Interaction contexts where the command can be used
* @property {EntryPointCommandHandlerType} [handler] Whether the interaction is handled by the app's
* interactions handler or by Discord.
*/
/**
@@ -419,7 +436,8 @@ class ApplicationCommand extends Base {
this.descriptionLocalizations ?? {},
) ||
!isEqual(command.integrationTypes ?? command.integration_types ?? [], this.integrationTypes ?? []) ||
!isEqual(command.contexts ?? [], this.contexts ?? [])
!isEqual(command.contexts ?? [], this.contexts ?? []) ||
('handler' in command && command.handler !== this.handler)
) {
return false;
}

View File

@@ -122,6 +122,12 @@ class BaseInteraction extends Base {
* @type {?InteractionContextType}
*/
this.context = data.context ?? null;
/**
* Attachment size limit in bytes
* @type {number}
*/
this.attachmentSizeLimit = data.attachment_size_limit;
}
/**
@@ -219,6 +225,16 @@ class BaseInteraction extends Base {
);
}
/**
* Indicates whether this interaction is a {@link PrimaryEntryPointCommandInteraction}
* @returns {boolean}
*/
isPrimaryEntryPointCommand() {
return (
this.type === InteractionType.ApplicationCommand && this.commandType === ApplicationCommandType.PrimaryEntryPoint
);
}
/**
* Indicates whether this interaction is a {@link MessageComponentInteraction}
* @returns {boolean}

View File

@@ -163,6 +163,17 @@ class ClientApplication extends Application {
this.approximateUserInstallCount ??= null;
}
if ('approximate_user_authorization_count' in data) {
/**
* An approximate amount of users that have OAuth2 authorizations for this application.
*
* @type {?number}
*/
this.approximateUserAuthorizationCount = data.approximate_user_authorization_count;
} else {
this.approximateUserAuthorizationCount ??= null;
}
if ('guild_id' in data) {
/**
* The id of the guild associated with this application.

View File

@@ -64,8 +64,6 @@ class ClientUser extends User {
},
});
this.client.token = data.token;
this.client.rest.setToken(data.token);
const { updated } = this.client.actions.UserUpdate.handle(data);
return updated ?? this;
}

View File

@@ -152,6 +152,7 @@ class CommandInteraction extends BaseInteraction {
editReply() {}
deleteReply() {}
followUp() {}
launchActivity() {}
showModal() {}
sendPremiumRequired() {}
awaitModalSubmit() {}

View File

@@ -122,6 +122,20 @@ class GuildMember extends Base {
} else {
this.flags ??= new GuildMemberFlagsBitField().freeze();
}
if (data.avatar_decoration_data) {
/**
* The member avatar decoration's data
*
* @type {?AvatarDecorationData}
*/
this.avatarDecorationData = {
asset: data.avatar_decoration_data.asset,
skuId: data.avatar_decoration_data.sku_id,
};
} else {
this.avatarDecorationData = null;
}
}
_clone() {
@@ -166,6 +180,15 @@ class GuildMember extends Base {
return this.avatar && this.client.rest.cdn.guildMemberAvatar(this.guild.id, this.id, this.avatar, options);
}
/**
* A link to the member's avatar decoration.
*
* @returns {?string}
*/
avatarDecorationURL() {
return this.avatarDecorationData ? this.client.rest.cdn.avatarDecoration(this.avatarDecorationData.asset) : null;
}
/**
* A link to the member's banner.
* @param {ImageURLOptions} [options={}] Options for the banner URL
@@ -195,6 +218,16 @@ class GuildMember extends Base {
return this.bannerURL(options) ?? this.user.bannerURL(options);
}
/**
* A link to the member's guild avatar decoration if they have one.
* Otherwise, a link to their {@link User#avatarDecorationURL} will be returned.
*
* @returns {?string}
*/
displayAvatarDecorationURL() {
return this.avatarDecorationURL() ?? this.user.avatarDecorationURL();
}
/**
* The time this member joined the guild
* @type {?Date}
@@ -499,7 +532,10 @@ class GuildMember extends Base {
this.communicationDisabledUntilTimestamp === member.communicationDisabledUntilTimestamp &&
this.flags.bitfield === member.flags.bitfield &&
(this._roles === member._roles ||
(this._roles.length === member._roles.length && this._roles.every((role, i) => role === member._roles[i])))
(this._roles.length === member._roles.length &&
this._roles.every((role, index) => role === member._roles[index]))) &&
this.avatarDecorationData?.asset === member.avatarDecorationData?.asset &&
this.avatarDecorationData?.skuId === member.avatarDecorationData?.skuId
);
}
@@ -525,6 +561,7 @@ class GuildMember extends Base {
json.bannerURL = this.bannerURL();
json.displayAvatarURL = this.displayAvatarURL();
json.displayBannerURL = this.displayBannerURL();
json.avatarDecorationURL = this.avatarDecorationURL();
return json;
}
}

View File

@@ -97,6 +97,7 @@ class MessageComponentInteraction extends BaseInteraction {
followUp() {}
deferUpdate() {}
update() {}
launchActivity() {}
showModal() {}
sendPremiumRequired() {}
awaitModalSubmit() {}

View File

@@ -249,7 +249,9 @@ class MessagePayload {
username,
avatar_url: avatarURL,
allowed_mentions:
this.isMessage && this.target.author.id !== this.target.client.user.id ? undefined : allowedMentions,
this.isMessage && message_reference === undefined && this.target.author.id !== this.target.client.user.id
? undefined
: allowedMentions,
flags,
message_reference,
attachments: this.options.attachments,

View File

@@ -119,6 +119,7 @@ class ModalSubmitInteraction extends BaseInteraction {
deferUpdate() {}
update() {}
sendPremiumRequired() {}
launchActivity() {}
}
InteractionResponses.applyToClass(ModalSubmitInteraction, 'showModal');

View File

@@ -27,7 +27,7 @@ class PartialGroupDMChannel extends BaseChannel {
* The hash of the channel icon
* @type {?string}
*/
this.icon = data.icon;
this.icon = data.icon ?? null;
/**
* Recipient data received in a {@link PartialGroupDMChannel}.
@@ -39,7 +39,7 @@ class PartialGroupDMChannel extends BaseChannel {
* The recipients of this Group DM Channel.
* @type {PartialRecipient[]}
*/
this.recipients = data.recipients;
this.recipients = data.recipients ?? [];
/**
* A manager of the messages belonging to this channel

View File

@@ -0,0 +1,11 @@
'use strict';
const CommandInteraction = require('./CommandInteraction.js');
/**
* Represents a primary entry point command interaction.
* @extends {CommandInteraction}
*/
class PrimaryEntryPointCommandInteraction extends CommandInteraction {}
module.exports = PrimaryEntryPointCommandInteraction;

View File

@@ -69,6 +69,12 @@ class InteractionResponses {
* <warn>This option is deprecated. Use `withResponse` or fetch the response instead.</warn>
*/
/**
* Options for launching activity in response to a {@link BaseInteraction}
* @typedef {Object} LaunchActivityOptions
* @property {boolean} [withResponse] Whether to return an {@link InteractionCallbackResponse} as the response
*/
/**
* Options for showing a modal in response to a {@link BaseInteraction}
* @typedef {Object} ShowModalOptions
@@ -370,6 +376,25 @@ class InteractionResponses {
: new InteractionResponse(this, this.message.interactionMetadata?.id);
}
/**
* Launches this application's activity, if enabled
* @param {LaunchActivityOptions} [options={}] Options for launching the activity
* @returns {Promise<InteractionCallbackResponse|undefined>}
*/
async launchActivity({ withResponse } = {}) {
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
const response = await this.client.rest.post(Routes.interactionCallback(this.id, this.token), {
query: makeURLSearchParams({ with_response: withResponse ?? false }),
body: {
type: InteractionResponseType.LaunchActivity,
},
auth: false,
});
this.replied = true;
return withResponse ? new InteractionCallbackResponse(this.client, response) : undefined;
}
/**
* Shows a modal component
* @param {ModalBuilder|ModalComponentData|APIModalInteractionResponseCallbackData} modal The modal to show
@@ -450,6 +475,7 @@ class InteractionResponses {
'followUp',
'deferUpdate',
'update',
'launchActivity',
'showModal',
'sendPremiumRequired',
'awaitModalSubmit',

View File

@@ -152,7 +152,7 @@
/**
* @external APIMediaGalleryItem
* @se {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIMediaGalleryItem}
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIMediaGalleryItem}
*/
/**
@@ -370,6 +370,11 @@
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/EntitlementType}
*/
/**
* @external EntryPointCommandHandlerType
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/EntryPointCommandHandlerType}
*/
/**
* @external ForumLayoutType
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/ForumLayoutType}

View File

@@ -141,44 +141,7 @@ const { ComponentType } = require('discord-api-types/v10');
* @ignore
*/
function createComponent(data) {
if (data instanceof Component) {
return data;
}
switch (data.type) {
case ComponentType.ActionRow:
return new ActionRow(data);
case ComponentType.Button:
return new ButtonComponent(data);
case ComponentType.StringSelect:
return new StringSelectMenuComponent(data);
case ComponentType.TextInput:
return new TextInputComponent(data);
case ComponentType.UserSelect:
return new UserSelectMenuComponent(data);
case ComponentType.RoleSelect:
return new RoleSelectMenuComponent(data);
case ComponentType.MentionableSelect:
return new MentionableSelectMenuComponent(data);
case ComponentType.ChannelSelect:
return new ChannelSelectMenuComponent(data);
case ComponentType.Container:
return new ContainerComponent(data);
case ComponentType.TextDisplay:
return new TextDisplayComponent(data);
case ComponentType.File:
return new FileComponent(data);
case ComponentType.MediaGallery:
return new MediaGalleryComponent(data);
case ComponentType.Section:
return new SectionComponent(data);
case ComponentType.Separator:
return new SeparatorComponent(data);
case ComponentType.Thumbnail:
return new ThumbnailComponent(data);
default:
return new Component(data);
}
return data instanceof Component ? data : new (ComponentTypeToComponent[data.type] ?? Component)(data);
}
/**
@@ -188,30 +151,7 @@ function createComponent(data) {
* @ignore
*/
function createComponentBuilder(data) {
if (data instanceof ComponentBuilder) {
return data;
}
switch (data.type) {
case ComponentType.ActionRow:
return new ActionRowBuilder(data);
case ComponentType.Button:
return new ButtonBuilder(data);
case ComponentType.StringSelect:
return new StringSelectMenuBuilder(data);
case ComponentType.TextInput:
return new TextInputBuilder(data);
case ComponentType.UserSelect:
return new UserSelectMenuBuilder(data);
case ComponentType.RoleSelect:
return new RoleSelectMenuBuilder(data);
case ComponentType.MentionableSelect:
return new MentionableSelectMenuBuilder(data);
case ComponentType.ChannelSelect:
return new ChannelSelectMenuBuilder(data);
default:
return new ComponentBuilder(data);
}
return data instanceof ComponentBuilder ? data : new (ComponentTypeToBuilder[data.type] ?? ComponentBuilder)(data);
}
/**
@@ -274,3 +214,32 @@ const TextInputComponent = require('../structures/TextInputComponent');
const ThumbnailComponent = require('../structures/ThumbnailComponent');
const UserSelectMenuBuilder = require('../structures/UserSelectMenuBuilder');
const UserSelectMenuComponent = require('../structures/UserSelectMenuComponent');
const ComponentTypeToComponent = {
[ComponentType.ActionRow]: ActionRow,
[ComponentType.Button]: ButtonComponent,
[ComponentType.StringSelect]: StringSelectMenuComponent,
[ComponentType.TextInput]: TextInputComponent,
[ComponentType.UserSelect]: UserSelectMenuComponent,
[ComponentType.RoleSelect]: RoleSelectMenuComponent,
[ComponentType.MentionableSelect]: MentionableSelectMenuComponent,
[ComponentType.ChannelSelect]: ChannelSelectMenuComponent,
[ComponentType.Container]: ContainerComponent,
[ComponentType.TextDisplay]: TextDisplayComponent,
[ComponentType.File]: FileComponent,
[ComponentType.MediaGallery]: MediaGalleryComponent,
[ComponentType.Section]: SectionComponent,
[ComponentType.Separator]: SeparatorComponent,
[ComponentType.Thumbnail]: ThumbnailComponent,
};
const ComponentTypeToBuilder = {
[ComponentType.ActionRow]: ActionRowBuilder,
[ComponentType.Button]: ButtonBuilder,
[ComponentType.StringSelect]: StringSelectMenuBuilder,
[ComponentType.TextInput]: TextInputBuilder,
[ComponentType.UserSelect]: UserSelectMenuBuilder,
[ComponentType.RoleSelect]: RoleSelectMenuBuilder,
[ComponentType.MentionableSelect]: MentionableSelectMenuBuilder,
[ComponentType.ChannelSelect]: ChannelSelectMenuBuilder,
};

View File

@@ -2,6 +2,7 @@
const { isJSONEncodable } = require('@discordjs/util');
const snakeCase = require('lodash.snakecase');
const { resolvePartialEmoji } = require('./Util');
/**
* Transforms camel-cased keys into snake cased keys
@@ -13,7 +14,14 @@ function toSnakeCase(obj) {
if (obj instanceof Date) return obj;
if (isJSONEncodable(obj)) return toSnakeCase(obj.toJSON());
if (Array.isArray(obj)) return obj.map(toSnakeCase);
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), toSnakeCase(value)]));
return Object.fromEntries(
Object.entries(obj).map(([key, value]) => [
snakeCase(key),
// TODO: The special handling of 'emoji' is just a temporary fix for v14, will be dropped in v15.
// See https://github.com/discordjs/discord.js/issues/10909
key === 'emoji' && typeof value === 'string' ? resolvePartialEmoji(value) : toSnakeCase(value),
]),
);
}
/**

View File

@@ -0,0 +1,148 @@
'use strict';
const { readFile } = require('node:fs/promises');
const { createReadStream } = require('node:fs');
const path = require('node:path');
const { setTimeout: sleep } = require('node:timers/promises');
const util = require('node:util');
const { fetch } = require('undici');
const { Client, GatewayIntentBits, AttachmentBuilder, EmbedBuilder, MessageFlags, ComponentType } = require('../src');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
});
const buffer = l =>
fetch(l)
.then(res => res.arrayBuffer())
.then(Buffer.from);
const linkA = 'https://discord.js.org/static/logo.svg';
const fileA = path.join(__dirname, 'blobReach.png');
const embed = () => new EmbedBuilder();
const attach = (attachment, name) => new AttachmentBuilder(attachment, { name });
const tests = [
m => m.channel.send('x'),
m => m.channel.send({ content: 'x', embeds: [{ description: 'a' }] }),
m => m.channel.send({ embeds: [{ description: 'a' }] }),
m => m.channel.send({ files: [{ attachment: fileA }] }),
m =>
m.channel.send({
embeds: [{ description: 'a' }],
files: [{ attachment: fileA, name: 'xyz.png' }],
}),
m => m.channel.send({ content: 'x', embeds: [embed().setDescription('a')] }),
m => m.channel.send({ embeds: [embed().setDescription('a')] }),
m => m.channel.send({ embeds: [embed().setDescription('a'), embed().setDescription('b')] }),
m => m.channel.send({ content: 'x', files: [attach(fileA)] }),
m => m.channel.send({ files: [fileA] }),
m => m.channel.send({ files: [attach(fileA)] }),
async m => m.channel.send({ files: [await buffer(linkA)] }),
async m => m.channel.send({ files: [{ attachment: await buffer(linkA) }] }),
m => m.channel.send({ files: [attach(fileA), attach(fileA)] }),
m => m.channel.send({ embeds: [{ description: 'a' }] }).then(m2 => m2.edit('x')),
m => m.channel.send({ embeds: [embed().setDescription('a')] }).then(m2 => m2.edit('x')),
m => m.channel.send('x').then(m2 => m2.edit({ embeds: [{ description: 'a' }] })),
m => m.channel.send('x').then(m2 => m2.edit({ embeds: [embed().setDescription('a')] })),
m => m.channel.send({ embeds: [{ description: 'a' }] }).then(m2 => m2.edit({ content: 'x', embeds: [] })),
m => m.channel.send({ embeds: [embed().setDescription('a')] }).then(m2 => m2.edit({ content: 'x', embeds: [] })),
m => m.channel.send({ content: 'x', embeds: [embed().setDescription('a')], files: [attach(fileA)] }),
m => m.channel.send({ content: 'x', files: [attach(fileA), attach(fileA)] }),
m => m.channel.send({ embeds: [embed().setDescription('a')], files: [attach(fileA)] }),
m =>
m.channel.send({
embeds: [embed().setImage('attachment://two.png')],
files: [attach(fileA, 'two.png')],
}),
m => m.channel.send({ content: 'x', files: [attach(fileA)] }),
m => m.channel.send({ files: [fileA] }),
m => m.channel.send({ files: [attach(fileA)] }),
async m => m.channel.send({ files: [await readFile(fileA)] }),
m => m.channel.send({ content: 'x', files: [attach(createReadStream(fileA))] }),
m => m.channel.send({ files: [createReadStream(fileA)] }),
m => m.channel.send({ files: [{ attachment: createReadStream(fileA) }] }),
m => m.reply({ content: 'x', allowedMentions: { repliedUser: false } }),
m => m.reply({ content: 'x', allowedMentions: { repliedUser: true } }),
m => m.reply({ content: 'x' }),
m => m.reply({ content: `${m.author}`, allowedMentions: { repliedUser: false } }),
m => m.reply({ content: `${m.author}`, allowedMentions: { parse: ['users'], repliedUser: false } }),
m => m.reply({ content: `${m.author}`, allowedMentions: { parse: ['users'], repliedUser: true } }),
m => m.reply({ content: `${m.author}` }),
m => m.edit({ flags: MessageFlags.SuppressEmbeds }),
m => m.edit({ flags: MessageFlags.SuppressEmbeds, allowedMentions: { repliedUser: false } }),
m =>
m
.reply({ content: 'x', allowedMentions: { repliedUser: false } })
.then(msg => msg.edit({ content: 'a', allowedMentions: { repliedUser: true } })),
m =>
m.channel.send({
components: [{ type: ComponentType.TextDisplay, content: `${m.author}` }],
flags: MessageFlags.IsComponentsV2,
}),
m =>
m.channel.send({
components: [{ type: ComponentType.TextDisplay, content: `${m.author}` }],
flags: MessageFlags.IsComponentsV2,
allowedMentions: { parse: ['users'] },
}),
m =>
m.channel.send({
components: [{ type: ComponentType.TextDisplay, content: `${m.author}` }],
flags: MessageFlags.IsComponentsV2,
allowedMentions: { parse: [] },
}),
m =>
m.reply({
components: [{ type: ComponentType.TextDisplay, content: `${m.author}` }],
flags: MessageFlags.IsComponentsV2,
allowedMentions: { parse: [], repliedUser: true },
}),
m =>
m.reply({
components: [{ type: ComponentType.TextDisplay, content: `${m.author}` }],
flags: MessageFlags.IsComponentsV2,
allowedMentions: { parse: [], repliedUser: false },
}),
m => m.channel.send('Done!'),
];
client.on('messageCreate', async message => {
if (message.author.id !== process.env.OWNER) return;
const match = message.content.match(/^do (.+)$/);
if (match?.[1] === 'it') {
/* eslint-disable no-await-in-loop */
for (const [i, test] of tests.entries()) {
await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``);
await test(message).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``));
await sleep(1_000);
}
/* eslint-enable no-await-in-loop */
} else if (match) {
const n = parseInt(match[1]) || 0;
const test = tests.slice(n)[0];
const i = tests.indexOf(test);
await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``);
await test(message).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``));
}
});
client.login();
// eslint-disable-next-line no-console
process.on('unhandledRejection', console.error);

View File

@@ -213,6 +213,7 @@ import {
SeparatorSpacingSize,
APIFileComponent,
APIMessageTopLevelComponent,
EntryPointCommandHandlerType,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
@@ -480,6 +481,7 @@ export class ApplicationCommand<PermissionsFetchType = {}> extends Base {
public get manager(): ApplicationCommandManager;
public id: Snowflake;
public integrationTypes: ApplicationIntegrationType[] | null;
public handler: EntryPointCommandHandlerType | null;
public name: string;
public nameLocalizations: LocalizationMap | null;
public nameLocalized: string | null;
@@ -583,23 +585,6 @@ export type BooleanCache<Cached extends CacheType> = Cached extends 'cached' ? t
export abstract class CommandInteraction<Cached extends CacheType = CacheType> extends BaseInteraction<Cached> {
public type: InteractionType.ApplicationCommand;
public get command(): ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
public options: Omit<
CommandInteractionOptionResolver<Cached>,
| 'getMessage'
| 'getFocused'
| 'getMentionable'
| 'getRole'
| 'getUser'
| 'getMember'
| 'getAttachment'
| 'getNumber'
| 'getInteger'
| 'getString'
| 'getChannel'
| 'getBoolean'
| 'getSubcommandGroup'
| 'getSubcommand'
>;
public channelId: Snowflake;
public commandId: Snowflake;
public commandName: string;
@@ -632,6 +617,9 @@ export abstract class CommandInteraction<Cached extends CacheType = CacheType> e
public reply(
options: string | MessagePayload | InteractionReplyOptions,
): Promise<InteractionResponse<BooleanCache<Cached>>>;
public launchActivity(options: LaunchActivityOptions & { withResponse: true }): Promise<InteractionCallbackResponse>;
public launchActivity(options?: LaunchActivityOptions & { withResponse?: false }): Promise<undefined>;
public launchActivity(options?: LaunchActivityOptions): Promise<InteractionCallbackResponse | undefined>;
public showModal(
modal:
| JSONEncodable<APIModalInteractionResponseCallbackData>
@@ -1171,6 +1159,7 @@ export class ClientApplication extends Application {
public flags: Readonly<ApplicationFlagsBitField>;
public approximateGuildCount: number | null;
public approximateUserInstallCount: number | null;
public approximateUserAuthorizationCount: number | null;
public tags: string[];
public installParams: ClientApplicationInstallParams | null;
public integrationTypesConfig: IntegrationTypesConfiguration | null;
@@ -1439,6 +1428,23 @@ export class CommandInteractionOptionResolver<Cached extends CacheType = CacheTy
}
export class ContextMenuCommandInteraction<Cached extends CacheType = CacheType> extends CommandInteraction<Cached> {
public options: Omit<
CommandInteractionOptionResolver<Cached>,
| 'getMessage'
| 'getFocused'
| 'getMentionable'
| 'getRole'
| 'getUser'
| 'getMember'
| 'getAttachment'
| 'getNumber'
| 'getInteger'
| 'getString'
| 'getChannel'
| 'getBoolean'
| 'getSubcommandGroup'
| 'getSubcommand'
>;
public commandType: ApplicationCommandType.Message | ApplicationCommandType.User;
public targetId: Snowflake;
public inGuild(): this is ContextMenuCommandInteraction<'raw' | 'cached'>;
@@ -1447,6 +1453,15 @@ export class ContextMenuCommandInteraction<Cached extends CacheType = CacheType>
private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption<Cached>[];
}
export class PrimaryEntryPointCommandInteraction<
Cached extends CacheType = CacheType,
> extends CommandInteraction<Cached> {
public commandType: ApplicationCommandType.PrimaryEntryPoint;
public inGuild(): this is PrimaryEntryPointCommandInteraction<'raw' | 'cached'>;
public inCachedGuild(): this is PrimaryEntryPointCommandInteraction<'cached'>;
public inRawGuild(): this is PrimaryEntryPointCommandInteraction<'raw'>;
}
// tslint:disable-next-line no-empty-interface
export interface DMChannel
extends Omit<
@@ -1784,6 +1799,7 @@ export class GuildMember extends Base {
private constructor(client: Client<true>, data: RawGuildMemberData, guild: Guild);
private _roles: Snowflake[];
public avatar: string | null;
public avatarDecorationData: AvatarDecorationData | null;
public banner: string | null;
public get bannable(): boolean;
public get dmChannel(): DMChannel | null;
@@ -1811,6 +1827,7 @@ export class GuildMember extends Base {
public user: User;
public get voice(): VoiceState;
public avatarURL(options?: ImageURLOptions): string | null;
public avatarDecorationURL(): string | null;
public bannerURL(options?: ImageURLOptions): string | null;
public ban(options?: BanOptions): Promise<GuildMember>;
public disableCommunicationUntil(timeout: DateResolvable | null, reason?: string): Promise<GuildMember>;
@@ -1820,6 +1837,7 @@ export class GuildMember extends Base {
public deleteDM(): Promise<DMChannel>;
public displayAvatarURL(options?: ImageURLOptions): string;
public displayBannerURL(options?: ImageURLOptions): string | null;
public displayAvatarDecorationURL(): string | null;
public edit(options: GuildMemberEditOptions): Promise<GuildMember>;
public isCommunicationDisabled(): this is GuildMember & {
communicationDisabledUntilTimestamp: number;
@@ -2062,6 +2080,7 @@ export type Interaction<Cached extends CacheType = CacheType> =
| ChatInputCommandInteraction<Cached>
| MessageContextMenuCommandInteraction<Cached>
| UserContextMenuCommandInteraction<Cached>
| PrimaryEntryPointCommandInteraction<Cached>
| AnySelectMenuInteraction<Cached>
| ButtonInteraction<Cached>
| AutocompleteInteraction<Cached>
@@ -2102,6 +2121,7 @@ export class BaseInteraction<Cached extends CacheType = CacheType> extends Base
public locale: Locale;
public guildLocale: CacheTypeReducer<Cached, Locale>;
public entitlements: Collection<Snowflake, Entitlement>;
public attachmentSizeLimit: number;
public inGuild(): this is BaseInteraction<'raw' | 'cached'>;
public inCachedGuild(): this is BaseInteraction<'cached'>;
public inRawGuild(): this is BaseInteraction<'raw'>;
@@ -2110,6 +2130,7 @@ export class BaseInteraction<Cached extends CacheType = CacheType> extends Base
public isChatInputCommand(): this is ChatInputCommandInteraction<Cached>;
public isCommand(): this is CommandInteraction<Cached>;
public isContextMenuCommand(): this is ContextMenuCommandInteraction<Cached>;
public isPrimaryEntryPointCommand(): this is PrimaryEntryPointCommandInteraction<Cached>;
public isMessageComponent(): this is MessageComponentInteraction<Cached>;
public isMessageContextMenuCommand(): this is MessageContextMenuCommandInteraction<Cached>;
public isModalSubmit(): this is ModalSubmitInteraction<Cached>;
@@ -2537,6 +2558,9 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
public update(
options: string | MessagePayload | InteractionUpdateOptions,
): Promise<InteractionResponse<BooleanCache<Cached>>>;
public launchActivity(options: LaunchActivityOptions & { withResponse: true }): Promise<InteractionCallbackResponse>;
public launchActivity(options?: LaunchActivityOptions & { withResponse?: false }): Promise<undefined>;
public launchActivity(options?: LaunchActivityOptions): Promise<InteractionCallbackResponse | undefined>;
public showModal(
modal:
| JSONEncodable<APIModalInteractionResponseCallbackData>
@@ -2783,6 +2807,9 @@ export class ModalSubmitInteraction<Cached extends CacheType = CacheType> extend
public deferUpdate(options?: InteractionDeferUpdateOptions): Promise<InteractionResponse<BooleanCache<Cached>>>;
/** @deprecated Sending a premium-style button is the new Discord behaviour. */
public sendPremiumRequired(): Promise<void>;
public launchActivity(options: LaunchActivityOptions & { withResponse: true }): Promise<InteractionCallbackResponse>;
public launchActivity(options?: LaunchActivityOptions & { withResponse?: false }): Promise<undefined>;
public launchActivity(options?: LaunchActivityOptions): Promise<InteractionCallbackResponse | undefined>;
public inGuild(): this is ModalSubmitInteraction<'raw' | 'cached'>;
public inCachedGuild(): this is ModalSubmitInteraction<'cached'>;
public inRawGuild(): this is ModalSubmitInteraction<'raw'>;
@@ -3219,7 +3246,7 @@ export type SelectMenuType = APISelectMenuComponent['type'];
export interface SeparatorComponentData extends BaseComponentData {
spacing?: SeparatorSpacingSize;
dividier?: boolean;
divider?: boolean;
}
export class SeparatorComponent extends Component<APISeparatorComponent> {
private constructor(data: APISeparatorComponent);
@@ -5270,10 +5297,18 @@ export interface ChatInputApplicationCommandData extends BaseApplicationCommandD
options?: readonly ApplicationCommandOptionData[];
}
export interface PrimaryEntryPointCommandData extends BaseApplicationCommandData {
description?: string;
descriptionLocalizations?: LocalizationMap;
type: ApplicationCommandType.PrimaryEntryPoint;
handler?: EntryPointCommandHandlerType;
}
export type ApplicationCommandData =
| UserApplicationCommandData
| MessageApplicationCommandData
| ChatInputApplicationCommandData;
| ChatInputApplicationCommandData
| PrimaryEntryPointCommandData;
export interface ApplicationCommandChannelOptionData extends BaseApplicationCommandOptionsData {
type: CommandOptionChannelResolvableType;
@@ -5756,9 +5791,13 @@ export interface ClientEvents {
guildMembersChunk: [members: ReadonlyCollection<Snowflake, GuildMember>, guild: Guild, data: GuildMembersChunk];
guildMemberUpdate: [oldMember: GuildMember | PartialGuildMember, newMember: GuildMember];
guildUpdate: [oldGuild: Guild, newGuild: Guild];
guildSoundboardSoundCreate: [soundboardSound: SoundboardSound];
guildSoundboardSoundDelete: [soundboardSound: SoundboardSound | PartialSoundboardSound];
guildSoundboardSoundUpdate: [oldSoundboardSound: SoundboardSound | null, newSoundboardSound: SoundboardSound];
guildSoundboardSoundCreate: [soundboardSound: GuildSoundboardSound];
guildSoundboardSoundDelete: [soundboardSound: GuildSoundboardSound | PartialSoundboardSound];
guildSoundboardSoundUpdate: [
oldSoundboardSound: GuildSoundboardSound | null,
newSoundboardSound: GuildSoundboardSound,
];
guildSoundboardSoundsUpdate: [soundboardSounds: ReadonlyCollection<Snowflake, GuildSoundboardSound>, guild: Guild];
inviteCreate: [invite: Invite];
inviteDelete: [invite: Invite];
messageCreate: [message: OmitPartialGroupDMChannel<Message>];
@@ -5834,7 +5873,7 @@ export interface ClientEvents {
guildScheduledEventDelete: [guildScheduledEvent: GuildScheduledEvent | PartialGuildScheduledEvent];
guildScheduledEventUserAdd: [guildScheduledEvent: GuildScheduledEvent | PartialGuildScheduledEvent, user: User];
guildScheduledEventUserRemove: [guildScheduledEvent: GuildScheduledEvent | PartialGuildScheduledEvent, user: User];
soundboardSounds: [soundboardSounds: ReadonlyCollection<Snowflake, SoundboardSound>, guild: Guild];
soundboardSounds: [soundboardSounds: ReadonlyCollection<Snowflake, GuildSoundboardSound>, guild: Guild];
}
export interface ClientFetchInviteOptions {
@@ -7375,6 +7414,10 @@ export interface ShowModalOptions {
withResponse?: boolean;
}
export interface LaunchActivityOptions {
withResponse?: boolean;
}
export { Snowflake };
export type StageInstanceResolvable = StageInstance | Snowflake;

View File

@@ -218,6 +218,7 @@ import {
PollData,
UserManager,
InteractionCallbackResponse,
PrimaryEntryPointCommandInteraction,
GuildScheduledEventRecurrenceRuleOptions,
ThreadOnlyChannel,
SectionComponentData,
@@ -229,6 +230,7 @@ import {
SeparatorComponentData,
FileComponentData,
ContainerComponentData,
InteractionResponse,
} from '.';
import {
expectAssignable,
@@ -687,7 +689,7 @@ client.on('messageCreate', async message => {
const rawSeparator: SeparatorComponentData = {
type: ComponentType.Separator,
spacing: 1,
dividier: false,
divider: false,
};
const rawFile: FileComponentData = {
@@ -1889,6 +1891,11 @@ client.on('interactionCreate', async interaction => {
expectType<Promise<InteractionCallbackResponse>>(interaction.update({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<Message<true>>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
expectType<Promise<undefined>>(interaction.launchActivity({ withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.launchActivity({ withResponse: booleanValue }),
);
} else if (interaction.inRawGuild()) {
expectAssignable<MessageComponentInteraction>(interaction);
expectType<APIButtonComponent | APISelectMenuComponent>(interaction.component);
@@ -1905,6 +1912,11 @@ client.on('interactionCreate', async interaction => {
expectType<Promise<InteractionCallbackResponse>>(interaction.update({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<Message<false>>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
expectType<Promise<undefined>>(interaction.launchActivity({ withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.launchActivity({ withResponse: booleanValue }),
);
} else if (interaction.inGuild()) {
expectAssignable<MessageComponentInteraction>(interaction);
expectType<MessageActionRowComponent | APIButtonComponent | APISelectMenuComponent>(interaction.component);
@@ -1921,6 +1933,11 @@ client.on('interactionCreate', async interaction => {
expectType<Promise<InteractionCallbackResponse>>(interaction.update({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<Message>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
expectType<Promise<undefined>>(interaction.launchActivity({ withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.launchActivity({ withResponse: booleanValue }),
);
}
}
@@ -1960,6 +1977,11 @@ client.on('interactionCreate', async interaction => {
expectType<Promise<Message<true>>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message<true>>>(interaction.fetchReply());
expectType<Promise<Message<true>>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
expectType<Promise<undefined>>(interaction.launchActivity({ withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.launchActivity({ withResponse: booleanValue }),
);
} else if (interaction.inRawGuild()) {
expectAssignable<ContextMenuCommandInteraction>(interaction);
expectType<null>(interaction.guild);
@@ -1970,6 +1992,11 @@ client.on('interactionCreate', async interaction => {
expectType<Promise<Message<false>>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message<false>>>(interaction.fetchReply());
expectType<Promise<Message<false>>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
expectType<Promise<undefined>>(interaction.launchActivity({ withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.launchActivity({ withResponse: booleanValue }),
);
} else if (interaction.inGuild()) {
expectAssignable<ContextMenuCommandInteraction>(interaction);
expectType<Guild | null>(interaction.guild);
@@ -1980,6 +2007,11 @@ client.on('interactionCreate', async interaction => {
expectType<Promise<Message>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message>>(interaction.fetchReply());
expectType<Promise<Message>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
expectType<Promise<undefined>>(interaction.launchActivity({ withResponse: false }));
expectType<Promise<InteractionCallbackResponse | undefined>>(
interaction.launchActivity({ withResponse: booleanValue }),
);
}
}
@@ -2164,6 +2196,57 @@ client.on('interactionCreate', async interaction => {
interaction.options.getMessage('name');
}
if (
interaction.type === InteractionType.ApplicationCommand &&
interaction.commandType === ApplicationCommandType.PrimaryEntryPoint
) {
expectType<PrimaryEntryPointCommandInteraction>(interaction);
// @ts-expect-error No options on primary entry point commands
interaction.options;
if (interaction.inCachedGuild()) {
expectAssignable<PrimaryEntryPointCommandInteraction>(interaction);
expectAssignable<Guild>(interaction.guild);
expectAssignable<CommandInteraction<'cached'>>(interaction);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<InteractionResponse<true>>>(interaction.deferReply());
expectType<Promise<InteractionResponse<true>>>(interaction.reply({ content: 'a', withResponse: false }));
expectType<Promise<InteractionResponse<true>>>(interaction.deferReply({ withResponse: false }));
expectType<Promise<Message<true>>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message<true>>>(interaction.fetchReply());
expectType<Promise<Message<true>>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
expectType<Promise<undefined>>(interaction.launchActivity({ withResponse: false }));
} else if (interaction.inRawGuild()) {
expectAssignable<PrimaryEntryPointCommandInteraction>(interaction);
expectType<null>(interaction.guild);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<InteractionResponse<false>>>(interaction.deferReply());
expectType<Promise<InteractionResponse<false>>>(interaction.reply({ content: 'a', withResponse: false }));
expectType<Promise<InteractionResponse<false>>>(interaction.deferReply({ withResponse: false }));
expectType<Promise<Message<false>>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message<false>>>(interaction.fetchReply());
expectType<Promise<Message<false>>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
expectType<Promise<undefined>>(interaction.launchActivity({ withResponse: false }));
} else if (interaction.inGuild()) {
expectAssignable<PrimaryEntryPointCommandInteraction>(interaction);
expectType<Guild | null>(interaction.guild);
expectType<Promise<InteractionCallbackResponse>>(interaction.reply({ content: 'a', withResponse: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferReply({ withResponse: true }));
expectType<Promise<InteractionResponse>>(interaction.deferReply());
expectType<Promise<InteractionResponse>>(interaction.reply({ content: 'a', withResponse: false }));
expectType<Promise<InteractionResponse>>(interaction.deferReply({ withResponse: false }));
expectType<Promise<Message>>(interaction.editReply({ content: 'a' }));
expectType<Promise<Message>>(interaction.fetchReply());
expectType<Promise<Message>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
expectType<Promise<undefined>>(interaction.launchActivity({ withResponse: false }));
}
}
if (interaction.isRepliable()) {
expectAssignable<RepliableInteraction>(interaction);
interaction.reply('test');
@@ -2192,6 +2275,7 @@ client.on('interactionCreate', async interaction => {
expectType<Promise<Message<true>>>(interaction.deferUpdate({ fetchReply: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<Message<true>>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
} else if (interaction.inRawGuild()) {
expectAssignable<ModalSubmitInteraction>(interaction);
expectType<null>(interaction.guild);
@@ -2204,6 +2288,7 @@ client.on('interactionCreate', async interaction => {
expectType<Promise<Message<false>>>(interaction.deferUpdate({ fetchReply: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<Message<false>>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
} else if (interaction.inGuild()) {
expectAssignable<ModalSubmitInteraction>(interaction);
expectType<Guild | null>(interaction.guild);
@@ -2216,6 +2301,7 @@ client.on('interactionCreate', async interaction => {
expectType<Promise<Message>>(interaction.deferUpdate({ fetchReply: true }));
expectType<Promise<InteractionCallbackResponse>>(interaction.deferUpdate({ withResponse: true }));
expectType<Promise<Message>>(interaction.followUp({ content: 'a' }));
expectType<Promise<InteractionCallbackResponse>>(interaction.launchActivity({ withResponse: true }));
}
}

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/rest",
"version": "2.5.0",
"version": "2.5.1",
"description": "The REST API for discord.js",
"scripts": {
"test": "vitest run",
@@ -91,7 +91,7 @@
"discord-api-types": "^0.38.1",
"magic-bytes.js": "^1.10.0",
"tslib": "^2.6.3",
"undici": "6.21.1"
"undici": "6.21.3"
},
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",

View File

@@ -2,6 +2,37 @@
All notable changes to this project will be documented in this file.
# [@discordjs/ws@2.0.3](https://github.com/discordjs/discord.js/compare/@discordjs/ws@2.0.2...@discordjs/ws@2.0.3) - (2025-06-16)
## Bug Fixes
- Regression in allowedMentions when replying (#10866) ([2ebb5cb](https://github.com/discordjs/discord.js/commit/2ebb5cbd53d869a52cba4549e7acc417963741cd))
# [@discordjs/ws@2.0.0](https://github.com/discordjs/discord.js/compare/@discordjs/ws@1.1.1...@discordjs/ws@2.0.0) - (2024-09-02)
## Bug Fixes
- **WebSocketShard:** Buffer native zlib decompression payload (#10416) ([defb083](https://github.com/discordjs/discord.js/commit/defb083528ef31383778187a04ced8b00d886242)) by @didinele
- **WebSocketManager:** Heartbeat event had outdated types (#10417) ([5eabec1](https://github.com/discordjs/discord.js/commit/5eabec14d45ef7bdd7f610e84234eb63e726eacd)) by @didinele
- Retry for EAI_AGAIN I/O error (#10383) ([be04acd](https://github.com/discordjs/discord.js/commit/be04acd534d7d0c3fb7f6bd174e4a6482aae0d73)) by @didinele
- Consistent debug log spacing (#10349) ([38c699b](https://github.com/discordjs/discord.js/commit/38c699bc8a2ca40f37f70c93e08067e00f12ee81)) by @Jiralite
## Features
- **WebsocketManager:** Retroactive token setting (#10418) ([de94eaf](https://github.com/discordjs/discord.js/commit/de94eaf351a69fab57ec766bd9e90e8c05e8c3d1)) by @didinele
- **WebSocketShard:** Explicit time out network error handling (#10375) ([093ac92](https://github.com/discordjs/discord.js/commit/093ac924aef1bf328feadb49876bfbe26052fe1a)) by @didinele
## Refactor
- **WebSocketShard:** Error event handling (#10436) ([a6de270](https://github.com/discordjs/discord.js/commit/a6de2707fc1107262b12491f73b5b6887df91c67)) by @didinele
- **ws:** Event layout (#10376) ([bf6761a](https://github.com/discordjs/discord.js/commit/bf6761a44adec1fe5017f6bf5d8bc0734916961f)) by @didinele
- **BREAKING CHANGE:** All events now emit shard id as its own param
* fix: worker event forwarding
---------
- Native zlib support (#10316) ([94cc02a](https://github.com/discordjs/discord.js/commit/94cc02a2580496774d75673abc0caabc765d9ee0)) by @sdanialraza
# [@discordjs/ws@2.0.0](https://github.com/discordjs/discord.js/compare/@discordjs/ws@1.1.1...@discordjs/ws@2.0.0) - (2024-09-02)
## Bug Fixes

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@discordjs/ws",
"version": "2.0.2",
"version": "2.0.3",
"description": "Wrapper around Discord's gateway",
"scripts": {
"test": "vitest run",
@@ -100,9 +100,9 @@
"tsup": "^8.2.4",
"turbo": "^2.0.14",
"typescript": "~5.5.4",
"undici": "6.21.1",
"undici": "6.21.3",
"vitest": "^2.0.5",
"zlib-sync": "^0.1.9"
"zlib-sync": "^0.1.10"
},
"engines": {
"node": ">=20"

62
pnpm-lock.yaml generated
View File

@@ -932,8 +932,8 @@ importers:
packages/discord.js:
dependencies:
'@discordjs/builders':
specifier: ^1.11.1
version: 1.11.1
specifier: ^1.11.2
version: 1.11.2
'@discordjs/collection':
specifier: 1.5.3
version: 1.5.3
@@ -947,8 +947,8 @@ importers:
specifier: workspace:^
version: link:../util
'@discordjs/ws':
specifier: ^1.2.2
version: 1.2.2(bufferutil@4.0.8)(utf-8-validate@6.0.4)
specifier: ^1.2.3
version: 1.2.3(bufferutil@4.0.8)(utf-8-validate@6.0.4)
'@sapphire/snowflake':
specifier: 3.5.3
version: 3.5.3
@@ -968,8 +968,8 @@ importers:
specifier: ^2.6.3
version: 2.6.3
undici:
specifier: 6.21.1
version: 6.21.1
specifier: 6.21.3
version: 6.21.3
devDependencies:
'@discordjs/api-extractor':
specifier: workspace:^
@@ -1331,8 +1331,8 @@ importers:
specifier: ^2.6.3
version: 2.6.3
undici:
specifier: 6.21.1
version: 6.21.1
specifier: 6.21.3
version: 6.21.3
devDependencies:
'@discordjs/api-extractor':
specifier: workspace:^
@@ -1774,14 +1774,14 @@ importers:
specifier: ~5.5.4
version: 5.5.4
undici:
specifier: 6.21.1
version: 6.21.1
specifier: 6.21.3
version: 6.21.3
vitest:
specifier: ^2.0.5
version: 2.0.5(@edge-runtime/vm@3.2.0)(@types/node@18.19.45)(happy-dom@14.12.3)(terser@5.39.0)
zlib-sync:
specifier: ^0.1.9
version: 0.1.9
specifier: ^0.1.10
version: 0.1.10
packages:
@@ -2789,8 +2789,8 @@ packages:
resolution: {integrity: sha512-4JINx4Rttha29f50PBsJo48xZXx/He5yaIWJRwVarhYAN947+S84YciHl+AIhQNRPAFkg8+5qFngEGtKxQDWXA==}
engines: {node: '>=18.18.0'}
'@discordjs/builders@1.11.1':
resolution: {integrity: sha512-2zDAVuoeAkdv0YQzYKO8vZfaDfB+1KZ60ymBKtD7QDpsh6lzAnQSUBLqeRkhlons6BT9+yRctOh9fPy94w6kDA==}
'@discordjs/builders@1.11.2':
resolution: {integrity: sha512-F1WTABdd8/R9D1icJzajC4IuLyyS8f3rTOz66JsSI3pKvpCAtsMBweu8cyNYsIyvcrKAVn9EPK+Psoymq+XC0A==}
engines: {node: '>=16.11.0'}
'@discordjs/collection@1.5.3':
@@ -2805,16 +2805,16 @@ packages:
resolution: {integrity: sha512-5cnX+tASiPCqCWtFcFslxBVUaCetB0thvM/JyavhbXInP1HJIEU+Qv/zMrnuwSsX3yWH2lVXNJZeDK3EiP4HHg==}
engines: {node: '>=16.11.0'}
'@discordjs/rest@2.5.0':
resolution: {integrity: sha512-PWhchxTzpn9EV3vvPRpwS0EE2rNYB9pvzDU/eLLW3mByJl0ZHZjHI2/wA8EbH2gRMQV7nu+0FoDF84oiPl8VAQ==}
'@discordjs/rest@2.5.1':
resolution: {integrity: sha512-Tg9840IneBcbrAjcGaQzHUJWFNq1MMWZjTdjJ0WS/89IffaNKc++iOvffucPxQTF/gviO9+9r8kEPea1X5J2Dw==}
engines: {node: '>=18'}
'@discordjs/util@1.1.1':
resolution: {integrity: sha512-eddz6UnOBEB1oITPinyrB2Pttej49M9FZQY8NxgEvc3tq6ZICZ19m70RsmzRdDHk80O9NoYN/25AqJl8vPVf/g==}
engines: {node: '>=18'}
'@discordjs/ws@1.2.2':
resolution: {integrity: sha512-dyfq7yn0wO0IYeYOs3z79I6/HumhmKISzFL0Z+007zQJMtAFGtt3AEoq1nuLXtcunUE5YYYQqgKvybXukAK8/w==}
'@discordjs/ws@1.2.3':
resolution: {integrity: sha512-wPlQDxEmlDg5IxhJPuxXr3Vy9AjYq5xCvFWGJyD7w7Np8ZGu+Mc+97LCoEc/+AYCo2IDpKioiH0/c/mj5ZR9Uw==}
engines: {node: '>=16.11.0'}
'@edge-runtime/format@2.2.1':
@@ -13977,6 +13977,10 @@ packages:
resolution: {integrity: sha512-q/1rj5D0/zayJB2FraXdaWxbhWiNKDvu8naDT2dl1yTlvJp4BLtOcp2a5BvgGNQpYYJzau7tf1WgKv3b+7mqpQ==}
engines: {node: '>=18.17'}
undici@6.21.3:
resolution: {integrity: sha512-gBLkYIlEnSp8pFbT64yFgGE6UIB9tAkhukC23PmMDCe5Nd+cRqKxSjw5y54MK2AZMgZfJWMaNE4nYUHgi1XEOw==}
engines: {node: '>=18.17'}
undici@7.8.0:
resolution: {integrity: sha512-vFv1GA99b7eKO1HG/4RPu2Is3FBTWBrmzqzO0mz+rLxN3yXkE4mqRcb8g8fHxzX4blEysrNZLqg5RbJLqX5buA==}
engines: {node: '>=20.18.1'}
@@ -14625,8 +14629,8 @@ packages:
engines: {node: '>=8.0.0'}
hasBin: true
zlib-sync@0.1.9:
resolution: {integrity: sha512-DinB43xCjVwIBDpaIvQqHbmDsnYnSt6HJ/yiB2MZQGTqgPcwBSZqLkimXwK8BvdjQ/MaZysb5uEenImncqvCqQ==}
zlib-sync@0.1.10:
resolution: {integrity: sha512-t7/pYg5tLBznL1RuhmbAt8rNp5tbhr+TSrJFnMkRtrGIaPJZ6Dc0uR4u3OoQI2d6cGlVI62E3Gy6gwkxyIqr/w==}
zod-validation-error@2.1.0:
resolution: {integrity: sha512-VJh93e2wb4c3tWtGgTa0OF/dTt/zoPCPzXq4V11ZjxmEAFaPi/Zss1xIZdEB5RD8GD00U0/iVXgqkF77RV7pdQ==}
@@ -16314,7 +16318,7 @@ snapshots:
tar-stream: 3.1.7
which: 4.0.0
'@discordjs/builders@1.11.1':
'@discordjs/builders@1.11.2':
dependencies:
'@discordjs/formatters': 0.6.1
'@discordjs/util': 1.1.1
@@ -16332,7 +16336,7 @@ snapshots:
dependencies:
discord-api-types: 0.38.1
'@discordjs/rest@2.5.0':
'@discordjs/rest@2.5.1':
dependencies:
'@discordjs/collection': 2.1.1
'@discordjs/util': 1.1.1
@@ -16342,14 +16346,14 @@ snapshots:
discord-api-types: 0.38.1
magic-bytes.js: 1.10.0
tslib: 2.8.1
undici: 6.21.1
undici: 6.21.3
'@discordjs/util@1.1.1': {}
'@discordjs/ws@1.2.2(bufferutil@4.0.8)(utf-8-validate@6.0.4)':
'@discordjs/ws@1.2.3(bufferutil@4.0.8)(utf-8-validate@6.0.4)':
dependencies:
'@discordjs/collection': 2.1.1
'@discordjs/rest': 2.5.0
'@discordjs/rest': 2.5.1
'@discordjs/util': 1.1.1
'@sapphire/async-queue': 1.5.3
'@types/ws': 8.5.12
@@ -24515,7 +24519,7 @@ snapshots:
espree: 10.1.0
esquery: 1.6.0
parse-imports: 2.1.1
semver: 7.6.3
semver: 7.7.1
spdx-expression-parse: 4.0.0
synckit: 0.9.1
transitivePeerDependencies:
@@ -24729,7 +24733,7 @@ snapshots:
natural-compare: 1.4.0
nth-check: 2.1.1
postcss-selector-parser: 6.1.2
semver: 7.6.3
semver: 7.7.1
vue-eslint-parser: 9.4.3(eslint@8.57.0)
xml-name-validator: 4.0.0
transitivePeerDependencies:
@@ -31404,6 +31408,8 @@ snapshots:
undici@6.21.1: {}
undici@6.21.3: {}
undici@7.8.0: {}
unicode-canonical-property-names-ecmascript@2.0.0: {}
@@ -32503,7 +32509,7 @@ snapshots:
optionalDependencies:
commander: 9.5.0
zlib-sync@0.1.9:
zlib-sync@0.1.10:
dependencies:
nan: 2.20.0