#What is the code structure for Modals

1 messages · Page 1 of 1 (latest)

tall kettle
#

Hey,

Using the unmerged PR about modals - how do you set it up? What props are required, where does it need to be imported on etc

tall kettle
#

Is it text input style or styles

wispy kayak
#

TextInputStyles.PARAGRAPH

tall kettle
#

nope still doesnt work

#

same error

#
                                                                                                                                                                                             ^

TypeError: Cannot read properties of undefined (reading 'PARAGRAPH')```
wispy kayak
#

well did you import it properly

tall kettle
#
    Client,
    Intents,
    MessageActionRow,
    MessageButton, Modal, TextInputStyles, TextInputComponent
} = require('discord.js');```
wispy kayak
#

one sec have to install it myself first

tall kettle
#

kk

#

TextInputStyles is undefined when logging

wispy kayak
#

"PARAGRAPH" should work

#

otherwise Constants.TextInputStyles.PARAGRAPH

tall kettle
#

okay progress has been made

#
DiscordAPIError: Invalid Form Body
data.components[0]: The specified component type is invalid in this context```
#
  httpStatus: 400,
  requestData: {
    json: {
      type: 9,
      data: {
        components: [
          {
            custom_id: 'text',
            label: 'Enter text',
            max_length: null,
            min_length: null,
            placeholder: null,
            required: false,
            style: 2,
            type: 4,
            value: null
          }
        ],
        custom_id: 'testing',
        title: 'Test modal!'
      }
    },
    files: []
  }
}```
wispy kayak
#

looks like .addComponents() takes ActionRows with TextInputComponent

tall kettle
#

so need to create an action row then?

#

const modal = new Modal().setTitle("Test modal!").setCustomId("testing").addComponents(new ActionRow().addComponents([new TextInputComponent().setCustomId("text").setLabel("Enter text").setStyle('PARAGRAPH')])) like this?

#

ActionRow is not a constructor

wispy kayak
#

sorry, in v13 its still MessageActionRow

tall kettle
#

thanks

#

It worked!!

#

Is there a way to add text inside it

#

as in not an input field but description

wispy kayak
#

not that I know

tall kettle
#

also how do i check in the interaction is its a modal

#
``` this doesnt work
wispy kayak
#

isModalSubmission()

tall kettle
#

Is this just cause I havent returned an interaction on click?

wispy kayak
#

you didn't reply, yes

tall kettle
#

kk

#

and replying auto closes

wispy kayak
#

no idea

#

I haven't tested it yet

tall kettle
#

yep it does

#

I assume theres no way to do validation and display an error

wispy kayak
#

validation in what form

tall kettle
#

Checking length, it contains certain text etc

wispy kayak
#

you can set the min and max length of the text

tall kettle
#

ahh okay

wispy kayak
#

discord displays an error

tall kettle
#

but thats about it?

wispy kayak
#

thats about it, yes

tall kettle
#

kk thanks

tight slate
#

can i ask how you handle the input data

wispy kayak
#

this is how I do it

#

You basically get a field value by using interaction.fields.getTextInputValue(id)