diff --git a/src/api/routes/guilds/#guild_id/application-command-index.ts b/src/api/routes/guilds/#guild_id/application-command-index.ts index 2162c1f4..006264ad 100644 --- a/src/api/routes/guilds/#guild_id/application-command-index.ts +++ b/src/api/routes/guilds/#guild_id/application-command-index.ts @@ -19,6 +19,7 @@ import { route } from "@spacebar/api"; import { Request, Response, Router } from "express"; import { Application, ApplicationCommand, Member, Snowflake } from "@spacebar/util"; +import { IsNull } from "typeorm"; const router = Router({ mergeParams: true }); @@ -30,7 +31,6 @@ router.get("/", route({}), async (req: Request, res: Response) => { applications.push(await Application.findOneOrFail({ where: { id: member.id } })); } - const applicationCommands: ApplicationCommand[] = []; const applicationsSendable = []; for (const application of applications) { @@ -42,13 +42,19 @@ router.get("/", route({}), async (req: Request, res: Response) => { id: application.id, name: application.name, }); + } - applicationCommands.push(await ApplicationCommand.findOneOrFail({ where: { application_id: application.id } })); + const globalApplicationCommands: ApplicationCommand[] = []; + const guildApplicationCommands: ApplicationCommand[] = []; + + for (const application of applications) { + globalApplicationCommands.push(await ApplicationCommand.findOneOrFail({ where: { application_id: application.id, guild_id: IsNull() } })); + guildApplicationCommands.push(await ApplicationCommand.findOneOrFail({ where: { application_id: application.id, guild_id: req.params.guild_id } })); } const applicationCommandsSendable = []; - for (const command of applicationCommands) { + for (const command of [...globalApplicationCommands, ...guildApplicationCommands]) { applicationCommandsSendable.push({ application_id: command.application_id, description: command.description,