1.1.0 • Published 1 year ago

modals-eris v1.1.0

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

eris-modals

a npm package to create Modals using the Discord API. It's focused on Eris

Modals-eris is a package that allows you tu create modals in the best way with any Discord bot library (discord.js, eris,...) We are bringing support in TutoDiscord (https://discord.gg/9jPjxMB). Developed by dirquel (TutoDiscord)

Create Modal in Eris

const Eris = require('eris'); //import Eris
const bot = new Eris('discord_secret_token') //Create the client
const { createModal } = require('modals-eris') //Require the package

bot.on('interactionCreate', async (interaction) => { //calling interactionCreate event
    if(interaction.custom_id == 'display_modal') { //if interaction's ID is "display_modal"
        await createModal(interaction, {
            title: 'título_del_modal',
            custom_id: 'myModal', //to interact in the future with the modal you need to set this ID.
            components: [ //add the action row to contain all the text inputs.
                {
                    type: 1, // the type of the action row
                    components: [ // to add the text inputs
                        {
                            type: 4, // the text input type 
                            custom_id: 'another_custom_id', // you need this id in order to know what did the user write here.
                            label: 'this is just a label... LOL', // label_that_will_be_shown_at_the_top_of_the_placeHolder
                            style: 1 // 1 for short input, 2 for paragraph input.
                            min_length: 1 // this is not compulsory. The minimum length the answer must have. (between 0 and 4000)
                            max_length: 20 // this is not compulsory. The maximum length the answer must have. (between 1 and 4000)
                            required: true // this is not compulsory. Boolean. If it's compulsory to answer this question before sending the modal or not.
                            value: 'hellooo' // this is not compulsory. Pre-filled value for this component (max 4000 characters)
                            placeholder: 'write something here' // this is not compulsory. Custom placeholder text if the input is empty (max 100 characters)
                        }
                    ]
                }
            ]
        })

        //////////////////////////////////////////////////////////////////////////////////////
        let Modal = {
            // Modal options
        }
        
        await createModal(interaction, Modal)
        //////////////////////////////////////////////////////////////////////////////////////
    }
})

bot.connect() //connect the bot to Discord.

Crear Modal Discord.js:

const Discord = require('discord.js');
const client = new Discord.Client({  });
const { createModal } = require('modals-eris');

client.on('interactionCreate', async (interaction) => { //los Modales solo se pueden crear a partir de interacciones (botones, selectMenus, etc.)
    if(interaction.isButton()) { //si un usuario interactúa con un botón es un botón
        await createModal(interaction, {
            title: 'título_del_modal',
            custom_id: 'myModal', //para poder interactuar más adelante con el Modal, necesitas añadirle una ID.
            components: [ //añades los placeholder, es decir, las líneas en las que el usuario podrá escribir dentro del modal.
                {
                    type: 1,
                    components: [
                        {
                            type: 4,
                            custom_id: 'another_custom_id',
                            label: 'etiqueta que saldrá encima del placeHolder.', //otra ID, esta vez para interacctuar con el placeHolder o línea de texto que estás creando en el Modal.
                            style: 1 //indicas que es un text input
                            min_length: 1 // no obligatorio. El número mínimo de caracteres que la respuesta debe tener. (entre 0 y 4000)
                            max_length: 20 // no obligatorio. El número máximo de caracteres que la respuesta debe tener. (entre 1 y 4000)
                            required: true // no obligatorio. Booleano. Si es obligatorio responder esta pregunta antes de enviar el Modal
                            value: 'holaaaa' // no obligatorio. Valor pre-escrito en este componente (max 4000 characters)
                            placeholder: 'escribe algo aquí' // no obligatorio. Placeholder predeterminado para este componente si el texto está vacío (máximo 100 caracteres)
                        }
                    ]
                }
            ]
        })
        ////////////////////////////////////////////////////////////////////////////////////
        let Modal = {
            //opciones
        };

        await createModal(interaction, Modal);
        ////////////////////////////////////////////////////////////////////////////////////
    }
})

client.login('discord_secret_token') //Conectar el bot a Discord.