sapphire-plugin-modal-commands

esm cjs deprecated
This plugin allows Discord bots using the [Sapphire Framework](https://npmjs.com/package/@sapphire/framework) to include modal submit logic in the same file as other command logic.
Version 2.0.2 License MIT
Keywords
sapphirepluginmodalcommandsdiscord.jsdiscorddiscord-modalsmodalstypescriptesmbot
INSTALL
Type:
<script src=" https://cdn.jsdelivr.net/npm/sapphire-plugin-modal-commands@2.0.2/dist/index.min.js "></script>
Sapphire Plugin Modal Commands
This plugin allows Discord bots using the Sapphire Framework to include modal submit logic in the same file as other command logic.
Example:
Typescript:
// src/lib/setup.ts
import 'sapphire-plugin-modal-commands/register';
// src/commands/modal.ts
import { Command, SapphireClient } from '@sapphire/framework';
import {
ActionRowBuilder,
ModalBuilder,
ModalActionRowComponentBuilder,
ModalSubmitInteraction,
TextInputComponent,
TextInputStyle,
} from 'discord.js';
export class UserCommand extends Command {
constructor(ctx: Command.Context, options: Command.Options) {
super(ctx, {
...options,
name: 'example',
chatInputCommand: {
register: true,
},
});
}
chatInputRun(interaction: Command.ChatInputInteraction) {
interaction.showModal(
new ModalBuilder()
.setTitle('Modal Example')
// format: (command name)--(customId)
// The separator can be changed in the client options (options.modalCommands.separator)
.setCustomId('example--example-modal')
.addComponents(
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(
new TextInputComponent()
.setLabel('Example Input')
.setCustomId('example-input')
.setStyle(TextInputStyle.Short)
.setRequired(true)
)
)
);
}
// Triggered on the modal submit
modalRun(interaction: ModalSubmitInteraction) {
interaction.reply('Submitted!');
}
}