From a257905561c2885ee991036ed6393b0507c5d7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Leit=C3=A3o?= <38259440+ImRodry@users.noreply.github.com> Date: Sat, 16 Nov 2024 01:17:51 +0000 Subject: [PATCH 1/4] fix(ApplicationCommand): remove false positives in equals This fixes a bug where having a local command that doesn't declare integrationTypes explicitly would cause it to not be equal to the command returned by Discord as they send a default value of [ 0 ] --- packages/discord.js/src/structures/ApplicationCommand.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/structures/ApplicationCommand.js b/packages/discord.js/src/structures/ApplicationCommand.js index 37eff9e46d5c..f70cfe73004a 100644 --- a/packages/discord.js/src/structures/ApplicationCommand.js +++ b/packages/discord.js/src/structures/ApplicationCommand.js @@ -418,7 +418,7 @@ class ApplicationCommand extends Base { command.descriptionLocalizations ?? command.description_localizations ?? {}, this.descriptionLocalizations ?? {}, ) || - !isEqual(command.integrationTypes ?? command.integration_types ?? [], this.integrationTypes ?? []) || + !isEqual(command.integrationTypes ?? command.integration_types ?? [0], this.integrationTypes ?? []) || !isEqual(command.contexts ?? [], this.contexts ?? []) ) { return false; From 0cbedd252d36f0b20243d8de75b5c7746c29c8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Leit=C3=A3o?= <38259440+ImRodry@users.noreply.github.com> Date: Sat, 16 Nov 2024 01:21:29 +0000 Subject: [PATCH 2/4] fix: also change default value in this --- packages/discord.js/src/structures/ApplicationCommand.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/discord.js/src/structures/ApplicationCommand.js b/packages/discord.js/src/structures/ApplicationCommand.js index f70cfe73004a..95aab94840d5 100644 --- a/packages/discord.js/src/structures/ApplicationCommand.js +++ b/packages/discord.js/src/structures/ApplicationCommand.js @@ -418,7 +418,8 @@ class ApplicationCommand extends Base { command.descriptionLocalizations ?? command.description_localizations ?? {}, this.descriptionLocalizations ?? {}, ) || - !isEqual(command.integrationTypes ?? command.integration_types ?? [0], this.integrationTypes ?? []) || + // [0] is the default value sent by Discord + !isEqual(command.integrationTypes ?? command.integration_types ?? [0], this.integrationTypes ?? [0]) || !isEqual(command.contexts ?? [], this.contexts ?? []) ) { return false; From b0bce5623baa9e005ab3695d44024ba5fc7c8c85 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Sun, 17 Nov 2024 02:08:19 +0000 Subject: [PATCH 3/4] fix: default to client config and use enum --- .../discord.js/src/structures/ApplicationCommand.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/src/structures/ApplicationCommand.js b/packages/discord.js/src/structures/ApplicationCommand.js index 95aab94840d5..66ecdbd0b273 100644 --- a/packages/discord.js/src/structures/ApplicationCommand.js +++ b/packages/discord.js/src/structures/ApplicationCommand.js @@ -1,7 +1,7 @@ 'use strict'; const { DiscordSnowflake } = require('@sapphire/snowflake'); -const { ApplicationCommandOptionType } = require('discord-api-types/v10'); +const { ApplicationCommandOptionType, ApplicationIntegrationType } = require('discord-api-types/v10'); const isEqual = require('fast-deep-equal'); const Base = require('./Base'); const ApplicationCommandPermissionsManager = require('../managers/ApplicationCommandPermissionsManager'); @@ -419,7 +419,13 @@ class ApplicationCommand extends Base { this.descriptionLocalizations ?? {}, ) || // [0] is the default value sent by Discord - !isEqual(command.integrationTypes ?? command.integration_types ?? [0], this.integrationTypes ?? [0]) || + !isEqual( + command.integrationTypes ?? + command.integration_types ?? + this.client.application.integrationTypesConfig?.keys() ?? [ApplicationIntegrationType.GuildInstall], + this.integrationTypes ?? + this.client.application.integrationTypesConfig?.keys() ?? [ApplicationIntegrationType.GuildInstall], + ) || !isEqual(command.contexts ?? [], this.contexts ?? []) ) { return false; From 00e432a39df28832bea0c42baedb92b77e720b6d Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Sat, 7 Dec 2024 23:02:49 +0000 Subject: [PATCH 4/4] fix: use Object.keys() --- packages/discord.js/src/structures/ApplicationCommand.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/src/structures/ApplicationCommand.js b/packages/discord.js/src/structures/ApplicationCommand.js index 66ecdbd0b273..9bda0c2458f0 100644 --- a/packages/discord.js/src/structures/ApplicationCommand.js +++ b/packages/discord.js/src/structures/ApplicationCommand.js @@ -422,9 +422,13 @@ class ApplicationCommand extends Base { !isEqual( command.integrationTypes ?? command.integration_types ?? - this.client.application.integrationTypesConfig?.keys() ?? [ApplicationIntegrationType.GuildInstall], + (this.client.application.integrationTypesConfig + ? Object.keys(this.client.application.integrationTypesConfig) + : [ApplicationIntegrationType.GuildInstall]), this.integrationTypes ?? - this.client.application.integrationTypesConfig?.keys() ?? [ApplicationIntegrationType.GuildInstall], + (this.client.application.integrationTypesConfig + ? Object.keys(this.client.application.integrationTypesConfig) + : [ApplicationIntegrationType.GuildInstall]), ) || !isEqual(command.contexts ?? [], this.contexts ?? []) ) {