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).
The code
Section titled “The code”// `/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();//! `/feedback` opens a form; the answer is thanked privately and posted to the channel.
use zaun_bot::prelude::*;
#[derive(Default)]struct Feedback;
impl Bot for Feedback { fn commands(&mut self, _: &Config) -> Vec<ApplicationCommand> { vec![SlashCommand::new("feedback", "Send feedback to the moderators").build()] }
fn on_command(&mut self, ctx: Context, _: CommandData) { let modal = Modal::new("feedback", "Feedback") .input("Subject", TextInput::short("subject").length(1, 80)) .input( "What should we know?", TextInput::paragraph("body") .length(10, 2000) .placeholder("Be specific"), ); let _ = ctx.show_modal(modal); }
fn on_modal(&mut self, ctx: Context, modal: ModalData) { let subject = modal.text("subject").unwrap_or("(none)"); let body = modal.text("body").unwrap_or_default(); let _ = ctx.reply_ephemeral("Thanks — your feedback was posted."); let card = EmbedBuilder::new() .title(format!("Feedback: {subject}")) .description(body) .footer(format!("from {}", ctx.member.display_name)); let _ = ctx.followup(card); }}
export_bot!(Feedback);The manifest
Section titled “The manifest”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]app_id = "org.zaun.examples.feedback"version = "0.1.0"name = "Feedback"description = "A /feedback form using a modal."permissions = ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"]
[capabilities]How it works
Section titled “How it works”- 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.
Run it
Section titled “Run it”git clone https://github.com/zaunchat/zaun-bot && cd zaun-bot/examples/ts/feedback-modalnpm installzbot build && zbot pack --unsignedzaun-host bot install --community <ID> *.zbot # on a host with allow_unsigned = truegit clone https://github.com/zaunchat/zaun-bot && cd zaun-bot/examples/rust/feedback-modalzbot build && zbot pack --unsignedzaun-host bot install --community <ID> *.zbot # on a host with allow_unsigned = true