Tengo este comando modal, quiero hacer que se muestre un modal al usuario cuando use el comando modal . ¿Hay algo malo con el siguiente código?
const { MessageActionRow, Modal, TextInputComponent } = require('discord.js'); client.on('interactionCreate', async (msg) => { if(msg.content === 'modal') { // Create the modal const modal = new Modal() .setCustomId('myModal') .setTitle('My Modal'); // Add components to modal // Create the text input components const favoriteColorInput = new TextInputComponent() .setCustomId('favoriteColorInput') // The label is the prompt the user sees for this input .setLabel("What's your favorite color?") // Short means only a single line of text .setStyle('SHORT'); const hobbiesInput = new TextInputComponent() .setCustomId('hobbiesInput') .setLabel("What's some of your favorite hobbies?") // Paragraph means multiple lines of text. .setStyle('PARAGRAPH'); // An action row only holds one text input, // so you need one action row per text input. const firstActionRow = new MessageActionRow().addComponents(favoriteColorInput); const secondActionRow = new MessageActionRow().addComponents(hobbiesInput); // Add inputs to the modal modal.addComponents(firstActionRow, secondActionRow); // Show the modal to the user await msg.showModal(modal); } });El evento interactionCreate se emite cuando se crea una interacción y toma un único parámetro, una Interaction que se creó. No es un message y no tiene propiedad de content . Como msg.content no está undefined , nunca coincidirá con la cadena "modal" , por lo que todo lo que está dentro de esa declaración if se ignora.
Si desea verificar si alguien envió un mensaje con la palabra modal como contenido, puede usar el evento messageCreate :
client.on('messageCreate', async (msg) => { if (msg.content === 'modal') { // ... El problema es que ese message no tiene un método showModal() , solo CommandInteraction , ButtonInteraction , SelectMenuInteraction , etc.
Si usa el evento interactionCreate , deberá verificar el nombre del comando, la ID del botón, etc. en su lugar:
client.on('interactionCreate', async (interaction) => { if (interaction.isCommand() && interaction.commandName === 'modal') { // ... // OR if (interaction.isButton() && interaction.customId === 'modal') { // ...