Add modal handling to interaction events and update CommandDefinition type
This commit is contained in:
13
src/index.ts
13
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);
|
||||
|
||||
2
src/type.d.ts
vendored
2
src/type.d.ts
vendored
@@ -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 }[]};
|
||||
Reference in New Issue
Block a user