(modals): Hook up modals. Pre-testing.

This commit is contained in:
2026-10-14 18:18:06 +08:00
parent 63152ffaf5
commit f17a3b5521
9 changed files with 24 additions and 8 deletions
+6 -7
View File
@@ -1,6 +1,7 @@
import { Client, GatewayIntentBits, MessageFlags, Partials } from 'discord.js';
import { Client, GatewayIntentBits, MessageFlags, ModalSubmitInteraction, Partials } from 'discord.js';
import { config } from './config';
import events from './events';
import modals from './modals';
import { Database } from './shared/Database';
import { openRedisClient } from './shared/RedisClient';
import { Handler } from './types';
@@ -38,7 +39,6 @@ const client = new Client({
const commands: Handler[] = [];
const contextMenus: Handler[] = [];
const buttons: Handler[] = [];
const modals: Handler[] = [];
const menus: Handler[] = [];
// Due to their reliance on each other, these two events (interactionCreate, and ready) have to stay here.
@@ -103,11 +103,12 @@ client.on('interactionCreate', async (interaction) => {
const id = interaction.customId.split('_')[0];
for (const modal of modals) {
if (id == modal.name) {
modal.handler(client, interaction, ...interaction.customId.split('_').slice(1));
if (id != modal.id) continue;
Promise.resolve((modal.execute as (context: Client, interaction: ModalSubmitInteraction, ...args: unknown[]) => Promise<void>)(client, interaction, ...interaction.customId.split('_').slice(1))
.catch(e => console.error('An error occurred while handling a modal interaction: ', e)));
return;
}
}
} else if (interaction.isAnySelectMenu()) {
// Handle menu selections.
const id = interaction.customId.split('_')[0];
@@ -127,14 +128,12 @@ client.on('clientReady', async () => {
await loadHandlersFrom('commands', commands);
await loadHandlersFrom('context-menus', contextMenus);
await loadHandlersFrom('buttons', buttons);
await loadHandlersFrom('modals', modals);
await loadHandlersFrom('menus', menus);
await refreshCommands(client);
await initIfNecessary(client, commands);
await initIfNecessary(client, buttons);
await initIfNecessary(client, modals);
await initIfNecessary(client, menus);
Encrypter.initialize(config.DATABASE_SECRET!);
+17
View File
@@ -0,0 +1,17 @@
import addKnowledgebaseItemModal from './addKnowledgebaseItemModal';
import addNoteModal from './addNoteModal';
import editKnowledgebaseItemModal from './editKnowledgebaseItemModal';
import openModTicket from './openModTicket';
import openTicketModal from './openTicketModal';
import reportMessage from './reportMessage';
import syncNameModal from './syncNameModal';
export default [
addKnowledgebaseItemModal,
addNoteModal,
editKnowledgebaseItemModal,
openModTicket,
openTicketModal,
reportMessage,
syncNameModal
];