aboutsummaryrefslogtreecommitdiff
path: root/examples/discord-interactions/commands/modal.ts
blob: ed4026ee09ced7b2b16b60fe4a88a65bc5f6a492 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { SlashCommand, ComponentType, TextInputStyle } from 'slash-create';

export default class ModalCommand extends SlashCommand {
  constructor(creator) {
    super(creator, {
      name: 'modal',
      description: 'Send a cool modal.'
    });

    this.filePath = __filename;
  }

  async run(ctx) {
    // You can send a modal this way
    // Keep in mind providing a callback is optional, but no callback requires the custom_id to be defined.
    ctx.sendModal(
      {
        title: 'Example Modal',
        components: [
          {
            type: ComponentType.ACTION_ROW,
            components: [
              {
                type: ComponentType.TEXT_INPUT,
                label: 'Text Input',
                style: TextInputStyle.SHORT,
                custom_id: 'text_input',
                placeholder: 'Type something...'
              }
            ]
          },
          {
            type: ComponentType.ACTION_ROW,
            components: [
              {
                type: ComponentType.TEXT_INPUT,
                label: 'Long Text Input',
                style: TextInputStyle.PARAGRAPH,
                custom_id: 'long_text_input',
                placeholder: 'Type something...'
              }
            ]
          }
        ]
      },
      (mctx) => {
        mctx.send(`Your input: ${mctx.values.text_input}\nYour long input: ${mctx.values.long_text_input}`);
      }
    );
  }
}