From 8904831e506d1d870d1d7b4e3af0f18a6c7633d3 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] 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 ] fix: use Object.keys() fix: default to client config and use enum fix: also change default value in this --- .../src/structures/ApplicationCommand.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/src/structures/ApplicationCommand.js b/packages/discord.js/src/structures/ApplicationCommand.js index 0403af955b44..4e8ac455b5a1 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 { ApplicationCommandPermissionsManager } = require('../managers/ApplicationCommandPermissionsManager.js'); const { PermissionsBitField } = require('../util/PermissionsBitField.js'); @@ -445,7 +445,18 @@ class ApplicationCommand extends Base { command.descriptionLocalizations ?? command.description_localizations ?? {}, this.descriptionLocalizations ?? {}, ) || - !isEqual(command.integrationTypes ?? command.integration_types ?? [], this.integrationTypes ?? []) || + // [0] is the default value sent by Discord + !isEqual( + command.integrationTypes ?? + command.integration_types ?? + (this.client.application.integrationTypesConfig + ? Object.keys(this.client.application.integrationTypesConfig) + : [ApplicationIntegrationType.GuildInstall]), + this.integrationTypes ?? + (this.client.application.integrationTypesConfig + ? Object.keys(this.client.application.integrationTypesConfig) + : [ApplicationIntegrationType.GuildInstall]), + ) || !isEqual(command.contexts ?? [], this.contexts ?? []) || ('handler' in command && command.handler !== this.handler) ) {