test

Constatic

Discord Bot BaseResponders

Modals

How to reply discord modals

Reply interaction with a modal

command.ts
import { createModalFields } from "@magicyan/discord";
// ...
interaction.showModal({
    customId: "form/modal",
    title: "Form",
    components: createModalFields({
        name:{
            label: "What's your name?",
            style: TextInputStyle.Short
        },
        age:{
            label: "What's your age?",
            style: TextInputStyle.Short
        },
    })
});
// ...

Reply to modal interaction

Reply a modal by setting the Responder type to modal.

responder.ts
new Responder({
    customId: "form/modal",
    type: ResponderType.Modal, cache: "cached",
    async run(interaction) {
        const { fields, member } = interaction;
        const name = fields.getTextInputValue("name");
        const age = fields.getTextInputValue("age");
 
        await registerMember(member, { name, age }); // Example function
 
        interaction.reply({ ephemeral, content: `Registered as ${name}` });
    },
});

On this page