Modal
Modals are popup forms that can collect detailed user input. They are particularly useful for complex interactions that require multiple fields or steps.
Usage
import { Modal, execute } from 'sunar';
const modal = new Modal({ id: 'example' });
execute(modal, (interaction) => {
// handle execution
});
export { modal };Implementation
The following example demonstrates how to implement a Modal using Sunar:
import { Modal, Slash, execute } from 'sunar';
import {
ActionRowBuilder,
ModalBuilder,
TextInputBuilder,
TextInputStyle,
} from 'discord.js';
const slash = new Slash({
name: 'feedback',
description: 'Send us feedback',
});
execute(slash, (interaction) => {
const contentInput = new TextInputBuilder()
.setCustomId('content')
.setLabel('Content')
.setStyle(TextInputStyle.Paragraph)
.setPlaceholder('Your feedback content...')
.setRequired(true);
const row = new ActionRowBuilder().setComponents(contentInput);
const modal = new ModalBuilder()
.setCustomId('feedbackModal')
.setTitle('Submit your feedback')
.setComponents(row);
interaction.showModal(modal);
});
const modal = new Modal({ id: 'feedbackModal' });
execute(modal, (interaction) => {
const feedback = interaction.fields.getTextInputValue('content');
// Send feedback somewhere...
interaction.reply({
content: 'Thanks for the feedback!',
ephemeral: true,
});
});
export { slash, modal };Reference
ModalOptions
Prop
Type
ModalConfig
Prop
Type
How is this guide?
Last updated on
ContextMenu
Context menu commands are available directly in the right-click context menu for users or messages. These commands are convenient for quick actions without needing to type a command.
Protector
Protectors in Sunar act as middleware, allowing you to intercept and control the flow of commands and interactions within your Discord bot. They provide a flexible way to enforce permissions, validate inputs, or perform pre-processing before executing commands.