From 0ffbef506a97a0bf22cb134fc007c2aec29cbffc Mon Sep 17 00:00:00 2001 From: Almeida Date: Fri, 24 Jun 2022 09:42:20 +0100 Subject: [PATCH] fix: edit() data can be partial and `defaultMemberPermissions` can be `null` (#8163) --- .../src/managers/ApplicationCommandManager.js | 2 +- .../discord.js/src/structures/ApplicationCommand.js | 4 ++-- packages/discord.js/typings/index.d.ts | 10 +++++----- packages/discord.js/typings/index.test-d.ts | 5 +++++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/discord.js/src/managers/ApplicationCommandManager.js b/packages/discord.js/src/managers/ApplicationCommandManager.js index a7287149884d..36b8fbcf26dc 100644 --- a/packages/discord.js/src/managers/ApplicationCommandManager.js +++ b/packages/discord.js/src/managers/ApplicationCommandManager.js @@ -173,7 +173,7 @@ class ApplicationCommandManager extends CachedManager { /** * Edits an application command. * @param {ApplicationCommandResolvable} command The command to edit - * @param {ApplicationCommandData|APIApplicationCommand} data The data to update the command with + * @param {Partial} data The data to update the command with * @param {Snowflake} [guildId] The guild's id where the command registered, * ignored when using a {@link GuildApplicationCommandManager} * @returns {Promise} diff --git a/packages/discord.js/src/structures/ApplicationCommand.js b/packages/discord.js/src/structures/ApplicationCommand.js index 70db0cb0cc08..159395af2816 100644 --- a/packages/discord.js/src/structures/ApplicationCommand.js +++ b/packages/discord.js/src/structures/ApplicationCommand.js @@ -232,7 +232,7 @@ class ApplicationCommand extends Base { /** * Edits this application command. - * @param {ApplicationCommandData} data The data to update the command with + * @param {Partial} data The data to update the command with * @returns {Promise} * @example * // Edit the description of this command @@ -300,7 +300,7 @@ class ApplicationCommand extends Base { /** * Edits the default member permissions of this ApplicationCommand - * @param {PermissionResolvable} defaultMemberPermissions The default member permissions required to run this command + * @param {?PermissionResolvable} defaultMemberPermissions The default member permissions required to run this command * @returns {Promise} */ setDefaultMemberPermissions(defaultMemberPermissions) { diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 604b526f89dc..67ce926a7039 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -328,7 +328,7 @@ export class ApplicationCommand extends Base { public type: ApplicationCommandType; public version: Snowflake; public delete(): Promise>; - public edit(data: ApplicationCommandData): Promise>; + public edit(data: Partial): Promise>; public setName(name: string): Promise>; public setNameLocalizations(nameLocalizations: LocalizationMap): Promise>; public setDescription(description: string): Promise>; @@ -336,7 +336,7 @@ export class ApplicationCommand extends Base { descriptionLocalizations: LocalizationMap, ): Promise>; public setDefaultMemberPermissions( - defaultMemberPermissions: PermissionResolvable, + defaultMemberPermissions: PermissionResolvable | null, ): Promise>; public setDMPermission(dmPermission?: boolean): Promise>; public setOptions(options: ApplicationCommandOptionData[]): Promise>; @@ -3188,11 +3188,11 @@ export class ApplicationCommandManager< public delete(command: ApplicationCommandResolvable, guildId?: Snowflake): Promise; public edit( command: ApplicationCommandResolvable, - data: ApplicationCommandDataResolvable, + data: Partial, ): Promise; public edit( command: ApplicationCommandResolvable, - data: ApplicationCommandDataResolvable, + data: Partial, guildId: Snowflake, ): Promise; public fetch( @@ -3690,7 +3690,7 @@ export interface BaseApplicationCommandData { name: string; nameLocalizations?: LocalizationMap; dmPermission?: boolean; - defaultMemberPermissions?: PermissionResolvable; + defaultMemberPermissions?: PermissionResolvable | null; } export interface AttachmentData { diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 297ee45eac99..ea224c443ec5 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -169,6 +169,11 @@ client.on('ready', async () => { const guildCommandFromGlobal = await client.application?.commands.fetch(guildCommandId, { guildId: testGuildId }); const guildCommandFromGuild = await client.guilds.cache.get(testGuildId)?.commands.fetch(guildCommandId); + await client.application?.commands.edit(globalCommandId, { defaultMemberPermissions: null }); + await globalCommand?.edit({ defaultMemberPermissions: null }); + await globalCommand?.setDefaultMemberPermissions(null); + await guildCommandFromGlobal?.edit({ dmPermission: false }); + // @ts-expect-error await client.guilds.cache.get(testGuildId)?.commands.fetch(guildCommandId, { guildId: testGuildId });