diff --git "a/src/api/routes/applications/\043application_id/commands/index.ts" "b/src/api/routes/applications/\043application_id/commands/index.ts" index a855b15..86057f5 100644 --- "a/src/api/routes/applications/\043application_id/commands/index.ts" +++ "b/src/api/routes/applications/\043application_id/commands/index.ts" @@ -20,6 +20,7 @@ import { route } from "@spacebar/api"; import { Request, Response, Router } from "express"; import { Application, ApplicationCommand, FieldErrors, Snowflake } from "@spacebar/util"; +import { IsNull } from "typeorm"; const router = Router({ mergeParams: true }); @@ -110,6 +111,16 @@ const body = req.body as ApplicationCommandCreateSchema[]; + // Remove commands not present in array + const applicationCommands = await ApplicationCommand.find({ where: { application_id: req.params.application_id, guild_id: IsNull() } }); + + const commandNamesInArray = body.map((c) => c.name); + const commandsNotInArray = applicationCommands.filter((c) => !commandNamesInArray.includes(c.name)); + + for (const command of commandsNotInArray) { + await ApplicationCommand.delete({ application_id: req.params.application_id, guild_id: IsNull(), id: command.id }); + } + for (const command of body) { if (!command.type) { command.type = 1; diff --git "a/src/api/routes/applications/\043application_id/guilds/\043guild_id/commands/index.ts" "b/src/api/routes/applications/\043application_id/guilds/\043guild_id/commands/index.ts" index 8e6fb78..111c26f 100644 --- "a/src/api/routes/applications/\043application_id/guilds/\043guild_id/commands/index.ts" +++ "b/src/api/routes/applications/\043application_id/guilds/\043guild_id/commands/index.ts" @@ -147,6 +147,16 @@ const body = req.body as ApplicationCommandCreateSchema[]; + // Remove commands not present in array + const applicationCommands = await ApplicationCommand.find({ where: { application_id: req.params.application_id, guild_id: req.params.guild_id } }); + + const commandNamesInArray = body.map((c) => c.name); + const commandsNotInArray = applicationCommands.filter((c) => !commandNamesInArray.includes(c.name)); + + for (const command of commandsNotInArray) { + await ApplicationCommand.delete({ application_id: req.params.application_id, guild_id: req.params.guild_id, id: command.id }); + } + for (const command of body) { if (!command.type) { command.type = 1;