From b5cf762730b21b4434bc0edb165c69e378fb9c22 Mon Sep 17 00:00:00 2001 From: CL TheDreWen Date: Fri, 28 Nov 2025 10:56:07 +0100 Subject: [PATCH] Add modal handling to interaction events and update CommandDefinition type --- src/index.ts | 13 +++++++++++++ src/type.d.ts | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e4fb9cf..403a4ea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,6 +50,19 @@ client.on(Events.InteractionCreate, async interaction => { return; } + if(interaction.isModalSubmit()) { + const id = interaction.customId; + commands.forEach((value) => { + if(value.modals) { + const button = value.modals.filter((b) => b.id == id); + if(button.length == 1) { + button[0]?.handle(interaction); + } + } + }); + return; + } + if (!interaction.isChatInputCommand()) return; const command = commands.get(interaction.commandName); diff --git a/src/type.d.ts b/src/type.d.ts index c5b5fb3..32f0360 100644 --- a/src/type.d.ts +++ b/src/type.d.ts @@ -1,3 +1,3 @@ import { ButtonInteraction, ChatInputCommandInteraction, SlashCommandOptionsOnlyBuilder } from "discord.js"; -export type CommandDefinition = { data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder, execute: (interaction: ChatInputCommandInteraction) => void, buttons?: { id: string, handle: (interaction: ButtonInteraction) => void}[]}; \ No newline at end of file +export type CommandDefinition = { data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder, execute: (interaction: ChatInputCommandInteraction) => void, buttons?: { id: string, handle: (interaction: ButtonInteraction) => void}[], modals?: { id: string, handle: (interaction: ModalSubmitInteraction) => void }[]}; \ No newline at end of file