diff --git a/src/handlers/interactionCommandHandler.ts b/src/handlers/interactionCommandHandler.ts index 8efb713..d928317 100644 --- a/src/handlers/interactionCommandHandler.ts +++ b/src/handlers/interactionCommandHandler.ts @@ -1,8 +1,9 @@ import { ChatInputCommandInteraction } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../services/logger'; -import { Command, ExtendedClient } from '../types/clientTypes'; +import { ExtendedClient } from '../types/clientTypes'; import { cannotSendMessageInChannel } from '../utils/validation/permissionValidator'; +import { BaseSlashCommandInteraction } from '../types/interactionTypes'; export const handleCommand = async ( interaction: ChatInputCommandInteraction, @@ -20,7 +21,9 @@ export const handleCommand = async ( logger.debug('Interaction deferred.'); // TODO: Update TS Type for command - const command: Command = client.commands?.get(interaction.commandName) as Command; + const command: BaseSlashCommandInteraction = client.commands!.get( + interaction.commandName + ) as BaseSlashCommandInteraction; if (!command) { logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`); return; diff --git a/src/interactions/commands/info/help.ts b/src/interactions/commands/info/help.ts index 2bddf4b..d1cc392 100644 --- a/src/interactions/commands/info/help.ts +++ b/src/interactions/commands/info/help.ts @@ -1,5 +1,11 @@ import config from 'config'; -import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; +import { + EmbedBuilder, + SharedSlashCommandOptions, + SlashCommandBuilder, + SlashCommandNumberOption, + SlashCommandStringOption +} from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../../../services/logger'; import { BotOptions, EmbedOptions } from '../../../types/configTypes'; @@ -27,16 +33,20 @@ const command: BaseSlashCommandInteraction = { }); // TODO: Create interface for command list - const commandList = client!.commands! - .filter((command) => { + const commandList = client! + .commands!.filter((command: BaseSlashCommandInteraction) => { // don't include system commands if (command.isSystemCommand) { return false; } return true; }) - .map((command) => { - const params: string = command.data.options[0] ? `**\`${command.data.options[0].name}\`**` + ' ' : ''; + .map((command: BaseSlashCommandInteraction) => { + let params: string = ''; + const option = command.data.options[0]; + if (option instanceof SlashCommandNumberOption || option instanceof SlashCommandStringOption) { + params = `**\`${option.name}\`**` + ' '; + } const beta: string = command.isBeta ? `${embedOptions.icons.beta} ` : ''; const newCommand: string = command.isNew ? `${embedOptions.icons.new} ` : ''; return `- **\`/${command.data.name}\`** ${params}- ${beta}${newCommand}${command.data.description}`; diff --git a/src/interactions/commands/player/test.ts b/src/interactions/commands/player/test.ts index af93a28..7bda8b7 100644 --- a/src/interactions/commands/player/test.ts +++ b/src/interactions/commands/player/test.ts @@ -1,7 +1,7 @@ import { EmbedBuilder, Message, SlashCommandBuilder } from 'discord.js'; -import { BaseCommandInteraction, BaseSlashCommandParams } from '../../../types/interactionTypes'; +import { BaseSlashCommandInteraction, BaseSlashCommandParams } from '../../../types/interactionTypes'; -export class TestCommandInteraction extends BaseCommandInteraction { +export class TestCommandInteraction extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder().setName('test').setDescription('Test command'); super(data); diff --git a/src/types/clientTypes.ts b/src/types/clientTypes.ts index dd99cd7..606a614 100644 --- a/src/types/clientTypes.ts +++ b/src/types/clientTypes.ts @@ -1,24 +1,9 @@ import { Client, Collection } from 'discord.js'; -import { BaseCommandInteraction } from './interactionTypes'; +import { BaseSlashCommandInteraction } from './interactionTypes'; type RegisterClientCommandsFunction = (params: { client: Client; executionId: string }) => void; -/* -export interface Command { - isNew?: boolean; - isBeta?: boolean; - isSystemCommand?: boolean; - data: { - name: string; - description: string; - options: SharedNameAndDescription[] - }; - execute: (params: { interaction: object; client: ExtendedClient | undefined; executionId: string }) => void; - autocomplete?: (params: { interaction: object; executionId: string }) => void; -} -*/ - export interface ExtendedClient extends Client { registerClientCommands?: RegisterClientCommandsFunction; - commands?: Collection; + commands?: Collection; } diff --git a/src/types/interactionTypes.ts b/src/types/interactionTypes.ts index a039df7..8b0168f 100644 --- a/src/types/interactionTypes.ts +++ b/src/types/interactionTypes.ts @@ -22,23 +22,16 @@ export interface BaseSlashCommandParams extends BaseInteractionParams { client?: ExtendedClient; } -interface BaseAutocompleteParams { +interface BaseAutocompleteParams extends BaseInteractionParams { interaction: AutocompleteInteraction; } -interface BaseComponentParams { +interface BaseComponentParams extends BaseInteractionParams { interaction: MessageComponentInteraction; referenceId?: string; } // Interaction types -export interface BaseSlashCommandInteraction { - isNew: boolean; - isBeta: boolean; - isSystemCommand?: boolean; - data: Omit; - execute(params: BaseSlashCommandParams): Promise | void>; -} export interface BaseAutocompleteInteraction { execute(params: BaseAutocompleteParams): Promise; @@ -87,7 +80,7 @@ abstract class BaseInteraction { ): Promise | ApplicationCommandOptionChoiceData | void>; } -export abstract class BaseCommandInteraction extends BaseInteraction { +export abstract class BaseSlashCommandInteraction extends BaseInteraction { data: Omit; isSystemCommand: boolean; isNew: boolean; diff --git a/src/utils/deploySlashCommands.ts b/src/utils/deploySlashCommands.ts index 8c27480..ff5b1f9 100644 --- a/src/utils/deploySlashCommands.ts +++ b/src/utils/deploySlashCommands.ts @@ -1,13 +1,7 @@ import 'dotenv/config'; import config from 'config'; -import { - REST, - RESTPostAPIChatInputApplicationCommandsJSONBody, - RouteLike, - Routes, - SlashCommandBuilder -} from 'discord.js'; +import { REST, RESTPostAPIChatInputApplicationCommandsJSONBody, RouteLike, Routes } from 'discord.js'; import fs from 'node:fs'; import path from 'node:path'; import { v4 as uuidv4 } from 'uuid';