feat: add feedback modal

This commit is contained in:
2024-12-13 20:57:22 +01:00
parent 5767c8c29e
commit 30303783f9
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import { commandModule, CommandType } from '@sern/handler';
import { EmbedBuilder } from 'discord.js';
export default commandModule({
type: CommandType.Modal,
async execute(modal) {
try {
const value = modal.fields.getTextInputValue('message');
const feedbackChannel = await modal.client.channels.fetch(process.env.FEEDBACK_CHANNEL_ID);
const embed = new EmbedBuilder({
description: value,
color: 0x00ff00,
});
feedbackChannel!.isSendable() &&
(await feedbackChannel.send({
content: `Feedback from ${modal.user.username}`,
embeds: [embed],
}));
modal.reply({ ephemeral: true, content: 'Sent! Thanks for the feedback!' });
} catch (error) {
console.error(error);
modal.reply({ ephemeral: true, content: 'An error occurred while sending your feedback. Please try again later.' });
}
},
});

24
src/commands/feedback.ts Normal file
View File

@@ -0,0 +1,24 @@
import { commandModule, CommandType } from '@sern/handler';
import { ActionRowBuilder, ModalActionRowComponentBuilder, ModalBuilder, TextInputBuilder, TextInputStyle } from 'discord.js';
export default commandModule({
type: CommandType.Slash,
plugins: [],
description: 'Feedback always welcome!',
options: [],
execute: async (ctx) => {
const modal = new ModalBuilder()
.setCustomId('feedback-modal')
.setTitle('ezbd Feedback');
const messageInput = new TextInputBuilder()
.setCustomId('message')
.setLabel('anything to fix? add?')
.setStyle(TextInputStyle.Paragraph);
const firstActionRow = new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(messageInput);
modal.addComponents(firstActionRow);
await ctx.interaction.showModal(modal);
},
});