Add modal handling to interaction events and update CommandDefinition type

This commit is contained in:
2025-11-28 10:56:07 +01:00
parent ce4996ae9d
commit b5cf762730
2 changed files with 14 additions and 1 deletions

View File

@@ -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);

2
src/type.d.ts vendored
View File

@@ -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}[]};
export type CommandDefinition = { data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder, execute: (interaction: ChatInputCommandInteraction) => void, buttons?: { id: string, handle: (interaction: ButtonInteraction) => void}[], modals?: { id: string, handle: (interaction: ModalSubmitInteraction) => void }[]};