2.0.2 • Published 1 year ago

sapphire-plugin-modal-commands v2.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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!');
  }
}
2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago