diff --git a/src/interactions/commands/Bot Creators/deploy/deploy.ts b/src/interactions/commands/Bot Creators/deploy/deploy.ts index c208cdab..b0a61cbc 100644 --- a/src/interactions/commands/Bot Creators/deploy/deploy.ts +++ b/src/interactions/commands/Bot Creators/deploy/deploy.ts @@ -2,8 +2,11 @@ import { ApplicationCommandOptionType, ApplicationCommandType, ApplicationIntegrationType, + ChatInputApplicationCommandData, InteractionContextType, + MessageApplicationCommandData, PermissionResolvable, + UserApplicationCommandData, } from "discord.js"; import { CommandCategory } from "@enums/core/CommandCategory"; import { SlashCommand } from "structures/core/SlashCommand"; @@ -36,72 +39,88 @@ export const run: SlashCommand["run"] = async (client, interaction) => { ApplicationCommandType.ChatInput) ); - if (type === ApplicationCommandType.PrimaryEntryPoint) { - return; - } + switch (type) { + case ApplicationCommandType.PrimaryEntryPoint: + return; - if (type === ApplicationCommandType.ChatInput) { - const command = client.interactions.chatInput.get(commandName); + case ApplicationCommandType.ChatInput: { + const command = client.interactions.chatInput.get(commandName); - if (!command) { - return InteractionHelper.reply(interaction, { - content: MessageCreator.createReject( - localization.getTranslation("commandNotFound"), - ), - }); - } + if (!command) { + return InteractionHelper.reply(interaction, { + content: MessageCreator.createReject( + localization.getTranslation("commandNotFound"), + ), + }); + } - let memberPermissions: PermissionResolvable[] | null = null; - - if ( - command.config.permissions && - command.config.integrationTypes?.includes( - ApplicationIntegrationType.GuildInstall, - ) - ) { - if (command.config.permissions.includes("BotOwner")) { - memberPermissions = ["Administrator"]; - } else if (!command.config.permissions.includes("Special")) { - memberPermissions = ( - command.config.permissions - ); + let memberPermissions: PermissionResolvable[] | null = null; + + if ( + command.config.permissions && + command.config.integrationTypes?.includes( + ApplicationIntegrationType.GuildInstall, + ) + ) { + if (command.config.permissions.includes("BotOwner")) { + memberPermissions = ["Administrator"]; + } else if (!command.config.permissions.includes("Special")) { + memberPermissions = ( + command.config.permissions + ); + } } - } - data = { - name: command.config.name, - description: command.config.description, - options: command.config.options, - defaultMemberPermissions: memberPermissions, - contexts: command.config.contexts ?? [ - InteractionContextType.Guild, - InteractionContextType.BotDM, - InteractionContextType.PrivateChannel, - ], - integrationTypes: command.config.integrationTypes ?? [ - ApplicationIntegrationType.GuildInstall, - ApplicationIntegrationType.UserInstall, - ], - }; - } else { - const command = ( - type === ApplicationCommandType.Message - ? client.interactions.contextMenu.message - : client.interactions.contextMenu.user - ).get(commandName); - - if (!command) { - return InteractionHelper.reply(interaction, { - content: MessageCreator.createReject( - localization.getTranslation("commandNotFound"), - ), - }); + data = { + name: command.config.name, + description: command.config.description, + options: command.config.options, + defaultMemberPermissions: memberPermissions, + contexts: command.config.contexts ?? [ + InteractionContextType.Guild, + InteractionContextType.BotDM, + InteractionContextType.PrivateChannel, + ], + integrationTypes: command.config.integrationTypes ?? [ + ApplicationIntegrationType.GuildInstall, + ApplicationIntegrationType.UserInstall, + ], + } satisfies ChatInputApplicationCommandData; + + break; } - data = { - name: command.config.name, - type: type, - }; + default: { + const command = ( + type === ApplicationCommandType.Message + ? client.interactions.contextMenu.message + : client.interactions.contextMenu.user + ).get(commandName); + + if (!command) { + return InteractionHelper.reply(interaction, { + content: MessageCreator.createReject( + localization.getTranslation("commandNotFound"), + ), + }); + } + + data = { + name: command.config.name, + type: type, + contexts: command.config.contexts ?? [ + InteractionContextType.Guild, + InteractionContextType.BotDM, + InteractionContextType.PrivateChannel, + ], + integrationTypes: command.config.integrationTypes ?? [ + ApplicationIntegrationType.GuildInstall, + ApplicationIntegrationType.UserInstall, + ], + } satisfies + | UserApplicationCommandData + | MessageApplicationCommandData; + } } await ( diff --git a/src/structures/core/ContextMenuCommand.ts b/src/structures/core/ContextMenuCommand.ts index 075a9c77..e9e458c6 100644 --- a/src/structures/core/ContextMenuCommand.ts +++ b/src/structures/core/ContextMenuCommand.ts @@ -1,5 +1,9 @@ import { Bot } from "@core/Bot"; -import { ContextMenuCommandInteraction } from "discord.js"; +import { + ApplicationIntegrationType, + ContextMenuCommandInteraction, + InteractionContextType, +} from "discord.js"; /** * Represents a command that is executed through context menus. @@ -25,6 +29,16 @@ export interface ContextMenuCommand { */ readonly name: string; + /** + * Interaction contexts where this command can be used, only for globally-scoped commands. Defaults to all interaction context types. + */ + readonly contexts?: InteractionContextType[]; + + /** + * Installation contexts where the command is available, only for globally-scoped commands. Defaults to all integration types. + */ + readonly integrationTypes?: ApplicationIntegrationType[]; + /** * The cooldown of the command, in seconds. */