1.0.10 • Published 3 years ago

discordjs-modal v1.0.10

Weekly downloads
-
License
GNU
Repository
-
Last release
3 years ago

Index

  • Description
  • Install
  • Report a bug
  • Incorporate to discord.js
    • Uploading the package to the main file
    • Working with events
    • Send modal
  • Documentation
    • Structures
      • Modal
        • Constructor
        • Properties
        • Methods
      • TextInput
        • Constructor
        • Properties
        • Methods
    • Events
      • modal
        • Example
    • Types
      • ModalOptions
      • TextInputOptions
      • TextInputStyles

Description

discordjs-modal is a dedicated package for developers who want to use the new modals in discord.js

Report a bug

Any bug that occurs while you are using discordjs-modal and the error is produced by discordjs-modal you can report it by contacting me through discord, tag: Risto#5227 Preferably send a screenshot of the console, a brief description of the error and in case of power, a capture or the code where the error is occurring

Incorporate to discord.js

Uploading the package to the main file

const { Client } = require('discord.js') // Get the Client class
const client = new Client({ intents: 32767 }) // Create a new Client
const discordjsModal = require('discordjs-modal') // Define this package
discordjsModal(client); // It is necessary to have your client to be able to know when a modal is executed

client.login('token') // Login with your discord bot

Send Modal

To send the Modal you need to execute an interaction before and the Modal to send. The client is automatically assigned a property which will allow you to send the Modal

Following the previous example where a Modal was created, we would send the Modal as follows:

client.modal.send(interaction, modal)

To receive the Modal you can go to the section event Modal example

Documentation

Structures

Modal

Constructor

new Modal(data)
ParameterTypeOptionalDefaultDescription
dataModalOptions or Modaltrue{ }Modal to clone or raw Modal data

Properties

.title

The title of this Modal

Return: ?string


.custom_id

A unique string that will be sent in the interaction when the Modal is sent

Return: ?string


.components

The components in this Modal

Return: ?Array<TextInput>

Methods

.setTitle(title)

Sets the title of this Modal

ParameterTypeDescription
titlestringThe title of this Modal

Return: Modal


.setCustomId(custom_id)

Sets the custom id for this Modal

ParameterTypeDescription
custom_idstringA unique string that will be sent in the interaction when the Modal is sent

Return: Modal


.addComponents(components)

Adds components to the Modal

ParameterTypeDescription
componentsArray<TextInput>The components to add

Return: Modal

Text Input

Constructor

new TextInput(data)
ParameterTypeOptionalDefaultDescription
dataTextInputOptionstrue{ }TextInput to clone or raw TextInput data

Properties

.custom_id

A unique string that will be sent in the interaction when the Modal is sent and TextInput is rellenated

Return ?string


.label

The label for this component

Return: ?string


.style

The style of this TextInput

Return: ?TextInputStyles


.min_length

The minimum input length for a text input, min 0, max 4000

Return: ?number

.max_length

The maximum input length for a text input, min 1, max 4000

Return: ?number


.placeholder

Placeholder text in the input

Return: ?string


.required

Whether the TextInput is required

Return: ?boolean

ParameterTypeDescription
custom_idstringA unique string that will be sent in the interaction when the Modal is sent and TextInput is rellenated

Return: TextInput


.setLabel(label)

Sets the label of this TextInput

ParameterTypeDescription
labelstringThe text to be displayed on this TextInput

Return: TextInput


.setStyle(style)

Sets the style of this TextInput

ParameterTypeDescription
styleTextInputStylesThe style of this component

Return: TextInput


.setMinLength(min_length)

The minimum input length for a text input, min 0, max 4000

ParameterTypeDescription
min_lengthnumberNumber of characters to be required

Return: TextInput


.setMaxLength(max_length)

The maximum input length for a text input, min 1, max 4000

ParameterTypeDescription
max_lengthnumberNumber of characters to be allowed

Return: TextInput


.setPlaceholder(placeholder)

Custom placeholder text if the input is empty, max 100 characters

ParameterTypeDescription
placeholderstringCustom placeholder text

Return: TextInput


.setRequired(required)

Custom placeholder text if the input is empty, max 100 characters

ParameterTypeDescription
requiredbooleanWhether the option is required

Events

This package emits an event when it detects a Modal. You will be shown how to interact with the event

ParameterTypeDescription
interactionInteractionThe received Modal

Types

ParameterTypeOptionalDefaultDescription
titlestringtruenoneThe title of the popup modal
custom_idstringtruenoneIdentifier for the component, max 100 characters
componentsTextInputOptionstruenoneBetween 1 and 5 (inclusive) components that make up the modal

NameValueDescription
Short1A single-line input
Paragraph2A multi-line input
1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.0-beta.2

3 years ago

1.0.0-beta.1

3 years ago

1.0.0-beta.0

3 years ago