(modals): Implement add-note-modal modal.

This commit is contained in:
2026-10-14 13:36:55 +08:00
parent 920fc347fb
commit 0fbb8918dc
+25 -27
View File
@@ -1,40 +1,38 @@
import { Client, MessageFlags, ModalSubmitInteraction } from 'discord.js'; import { Client, ModalSubmitInteraction } from 'discord.js';
import { Database } from '../shared/Database'; import { Database } from '../shared/Database';
import { logCustomEvent } from '../utils'; import { deferInteraction, logCustomEvent } from '../utils';
import { Modal } from '../types';
export default { class AddNoteModal implements Modal<Client> {
name: 'add-note-modal', id = 'add-note-modal';
handler: async function (client: Client, interaction: ModalSubmitInteraction, id: string) {
async execute(context: Client<boolean>, interaction: ModalSubmitInteraction, id: string): Promise<void> {
if (!interaction.inGuild()) return;
await deferInteraction(interaction);
try {
const message = interaction.fields.getTextInputValue('note-message'); const message = interaction.fields.getTextInputValue('note-message');
const guild = await context.guilds.fetch(interaction.guildId);
const user = await context.users.fetch(id);
const user = await client.users.fetch(id); await logCustomEvent(guild, {
logCustomEvent(interaction.guild!, {
title: 'Note Added', title: 'Note Added',
description: null, description: null,
color: 0x00FF00, color: 0x00FF00,
timestamp: new Date(), timestamp: new Date(),
fields: [ fields: [
{ { name: 'Moderator', value: `${interaction.user} (${interaction.user.id})`, inline: false },
name: 'Moderator', { name: 'User', value: `${user.username} (${user.id})`, inline: false },
value: `<@${interaction.user.id}>\n${interaction.user.username}`, { name: 'Note', value: message, inline: false },
inline: true ],
},
{
name: 'User',
value: `<@${id}>\n${user.username}`,
inline: true
},
{
name: 'Note',
value: message,
inline: true
}
]
}); });
await Database.putNote(id, message, interaction.user.id); await Database.putNote(id, message, interaction.user.id);
await interaction.editReply({ content: 'Note added.' });
interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Note added' }); } catch (error: Error | any) {
await interaction.editReply({ content: error.message }).catch(() => {});
} }
}; }
}
export default new AddNoteModal();