Skip to content

Feedback form (modal)

/feedback opens a form. When the member submits it, the bot thanks them privately and posts the feedback to the channel.

Source in zaun-bot: examples/ts/feedback-modal (TypeScript) and examples/rust/feedback-modal (Rust).

src/index.ts
// `/feedback` opens a form; the answer is thanked privately and posted to the channel.
import { Bot, EmbedBuilder, ModalBuilder, SlashCommandBuilder, TextInputBuilder, TextInputStyle } from '@zaun/bot';
const bot = new Bot();
bot.command(new SlashCommandBuilder().setName('feedback').setDescription('Send feedback to the moderators'), (interaction) => {
interaction.showModal(new ModalBuilder().setCustomId('feedback').setTitle('Feedback')
.addTextInput('Subject', new TextInputBuilder().setCustomId('subject').setStyle(TextInputStyle.Short).setMinLength(1).setMaxLength(80))
.addTextInput('What should we know?', new TextInputBuilder().setCustomId('body').setStyle(TextInputStyle.Paragraph)
.setMinLength(10).setMaxLength(2000).setPlaceholder('Be specific')));
});
bot.modal('feedback', (interaction) => {
const subject = interaction.fields.getTextInputValue('subject') || '(none)';
const body = interaction.fields.getTextInputValue('body');
interaction.reply({ content: 'Thanks — your feedback was posted.', ephemeral: true });
interaction.followUp(new EmbedBuilder().setTitle(`Feedback: ${subject}`).setDescription(body)
.setFooter({ text: `from ${interaction.member.displayName}` }));
});
export const { init, onEvent, onInteraction, onAutocomplete, onTimer, onVoiceEvent } = bot.exports();
zaun-bot.toml
app_id = "org.zaun.examples.ts-feedback"
version = "0.1.0"
name = "Feedback"
description = "A /feedback form using a modal."
permissions = ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"]
[capabilities]
  • The command answers by showing a modal, which counts as the first response.
  • The host checks the submission against the modal (lengths, required inputs) before the modal handler runs.
  • The modal handler answers with an ephemeral reply only the member sees, then a public follow-up embed.
Terminal window
git clone https://github.com/zaunchat/zaun-bot && cd zaun-bot/examples/ts/feedback-modal
npm install
zbot build && zbot pack --unsigned
zaun-host bot install --community <ID> *.zbot # on a host with allow_unsigned = true