diff --git a/JavaScript/publish.js b/JavaScript/publish.js index 6427e27..013a8dc 100644 --- a/JavaScript/publish.js +++ b/JavaScript/publish.js @@ -1,10 +1,10 @@ // @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"; @@ -44,8 +44,16 @@ export function publish(options) { 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.options ?? []) + : [], defaultMemberPermissions, dmPermission, }; @@ -53,7 +61,11 @@ export function publish(options) { 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)) { @@ -83,7 +95,9 @@ export function publish(options) { 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) { diff --git a/JavaScript/serverOnly.js b/JavaScript/serverOnly.js new file mode 100644 index 0000000..5cf5469 --- /dev/null +++ b/JavaScript/serverOnly.js @@ -0,0 +1,44 @@ +// @ts-nocheck + +/** + * Checks if a command is available in a specific server. + * + * @author @D3ord3NidAm [<@1017182455926624316>] + * @version 1.0.0 + * @example + * ```ts + * import { commandModule, CommandType } from "@sern/handler"; + * import { serverOnly } from "../plugins/serverOnly"; + * export default commandModule({ + * type: CommandType.Both, + * plugins: [serverOnly(["guildId"], failMessage)], // fail message is the message you will see when the command is ran in the wrong server. + * description: "command description", + * execute: async (ctx, args) => { + * // your code here + * }, + * }); + * ``` + */ +import { PluginType } from "@sern/handler"; +export function serverOnly( + guildId, + failMessage = "I am unable to comply with your command." +) { + return { + type: PluginType.Event, + description: "Checks if a command is available in a specific server.", + + async execute([ctx, args], controller) { + if (!guildId.includes(ctx.guildId)) { + await ctx.reply(failMessage).then(async (m) => { + setTimeout(async () => { + await m.delete(); + }, 3000); + }); + return controller.stop(); + } + + return controller.next(); + }, + }; +} diff --git a/TypeScript/serverOnly.ts b/TypeScript/serverOnly.ts index ac383fc..9e5536e 100644 --- a/TypeScript/serverOnly.ts +++ b/TypeScript/serverOnly.ts @@ -22,22 +22,22 @@ import { CommandType, EventPlugin, PluginType } from "@sern/handler"; export function serverOnly( - guildId: string[], - failMessage = "I am unable to comply with your command." + guildId: string[], + failMessage = "I am unable to comply with your command." ): EventPlugin { - return { - type: PluginType.Event, - description: "Checks if a command is available in a specific server.", - async execute([ctx, args], controller) { - if (!guildId.includes(ctx.guildId)) { - await ctx.reply(failMessage).then(async (m) => { - setTimeout(async () => { - await m.delete(); - }, 3000); - }); - return controller.stop(); - } - return controller.next(); - }, - }; + return { + type: PluginType.Event, + description: "Checks if a command is available in a specific server.", + async execute([ctx, args], controller) { + if (!guildId.includes(ctx.guildId)) { + await ctx.reply(failMessage).then(async (m) => { + setTimeout(async () => { + await m.delete(); + }, 3000); + }); + return controller.stop(); + } + return controller.next(); + }, + }; }