(selectInteraction, rootInteraction, state)
| 602 | } |
| 603 | |
| 604 | async function handleAddField(selectInteraction, rootInteraction, state) { |
| 605 | if (state.fields.length >= MAX_FIELDS) { |
| 606 | await selectInteraction.deferUpdate(); |
| 607 | await replyUserError(selectInteraction, { |
| 608 | type: ErrorTypes.VALIDATION, |
| 609 | message: `Embeds can have a maximum of ${MAX_FIELDS} fields.`, |
| 610 | }); |
| 611 | return; |
| 612 | } |
| 613 | |
| 614 | const modal = new ModalBuilder() |
| 615 | .setCustomId('eb_add_field') |
| 616 | .setTitle('Add Field'); |
| 617 | |
| 618 | const fieldNameLabel = new LabelBuilder() |
| 619 | .setLabel('Field Name (max 256 characters)') |
| 620 | .setTextInputComponent( |
| 621 | new TextInputBuilder() |
| 622 | .setCustomId('field_name') |
| 623 | .setStyle(TextInputStyle.Short) |
| 624 | .setMaxLength(256) |
| 625 | .setRequired(true) |
| 626 | .setPlaceholder('Field Title'), |
| 627 | ); |
| 628 | |
| 629 | const fieldValueLabel = new LabelBuilder() |
| 630 | .setLabel('Field Value (max 1024 characters)') |
| 631 | .setTextInputComponent( |
| 632 | new TextInputBuilder() |
| 633 | .setCustomId('field_value') |
| 634 | .setStyle(TextInputStyle.Paragraph) |
| 635 | .setMaxLength(1024) |
| 636 | .setRequired(true) |
| 637 | .setPlaceholder('Field content goes here...'), |
| 638 | ); |
| 639 | |
| 640 | const inlineRadio = new RadioGroupBuilder() |
| 641 | .setCustomId('field_inline') |
| 642 | .setRequired(false) |
| 643 | .addOptions([ |
| 644 | { label: 'No — full width', value: 'no' }, |
| 645 | { label: 'Yes — side-by-side', value: 'yes' }, |
| 646 | ]); |
| 647 | |
| 648 | const inlineLabel = new LabelBuilder() |
| 649 | .setLabel('Display inline?') |
| 650 | .setRadioGroupComponent(inlineRadio); |
| 651 | |
| 652 | modal.addLabelComponents(fieldNameLabel, fieldValueLabel, inlineLabel); |
| 653 | |
| 654 | const shown = await InteractionHelper.safeShowModal(selectInteraction, modal); |
| 655 | if (!shown) return; |
| 656 | |
| 657 | const submitted = await selectInteraction |
| 658 | .awaitModalSubmit({ |
| 659 | filter: i => i.customId === 'eb_add_field' && i.user.id === selectInteraction.user.id, |
| 660 | time: 120_000, |
| 661 | }) |
no test coverage detected