From 33416d246d2b253f4b6978f0ec50663542906586 Mon Sep 17 00:00:00 2001 From: Evo <85353424+EvolutionX-10@users.noreply.github.com> Date: Sat, 24 Sep 2022 23:46:29 +0530 Subject: [PATCH] feat(publish): support other types of application command (#41) --- TypeScript/publish.ts | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/TypeScript/publish.ts b/TypeScript/publish.ts index ec63167..da282cd 100644 --- a/TypeScript/publish.ts +++ b/TypeScript/publish.ts @@ -1,9 +1,9 @@ // @ts-nocheck /** - * This is publish plugin, it allows you to publish your slash commands with ease. + * This is publish plugin, it allows you to publish your application commands with ease. * * @author @EvolutionX-10 [<@697795666373640213>] - * @version 1.2.3 + * @version 1.3.0 * @example * ```ts * import { publish } from "../plugins/publish"; @@ -22,6 +22,7 @@ import { CommandType, PluginType, SernOptionsData, + SlashCommand, } from "@sern/handler"; import { ApplicationCommandData, @@ -31,7 +32,12 @@ import { export function publish( options?: PublishOptions -): CommandPlugin { +): CommandPlugin< + | CommandType.Slash + | CommandType.Both + | CommandType.MenuMsg + | CommandType.MenuUser +> { return { type: PluginType.Command, description: "Manage Slash Commands", @@ -56,8 +62,18 @@ export function publish( const commandData = { type: CommandTypeRaw[module.type], name: module.name!, - description: module.description, - options: optionsTransformer(module.options ?? []), + description: [CommandType.Slash, CommandType.Both].includes( + module.type + ) + ? module.description + : undefined, + options: [CommandType.Slash, CommandType.Both].includes( + module.type + ) + ? optionsTransformer( + (module as SlashCommand).options ?? [] + ) + : [], defaultMemberPermissions, dmPermission, } as ApplicationCommandData; @@ -65,7 +81,11 @@ export function publish( if (!guildIds.length) { const cmd = ( await client.application!.commands.fetch() - ).find((c) => c.name === module.name); + ).find( + (c) => + c.name === module.name && + c.type === CommandTypeRaw[module.type] + ); if (cmd) { if (!cmd.equals(commandData, true)) { console.log( @@ -92,7 +112,9 @@ export function publish( const guild = await client.guilds.fetch(id).catch(c); if (!guild) continue; const guildcmd = (await guild.commands.fetch()).find( - (c) => c.name === module.name + (c) => + c.name === module.name && + c.type === CommandTypeRaw[module.type] ); if (guildcmd) { if (!guildcmd.equals(commandData, true)) {