Why Modal Isn't Open

const { MessageActionRow, MessageButton, Modal, TextInputComponent } = require('discord.js');

module.exports = {
name: 'panel',
description: 'Send Panel',
run: async (client, interaction) => {
try {
const button1 = new MessageButton()
.setCustomId('btn1')
.setLabel('Avatar')
.setStyle('PRIMARY');
const button2 = new MessageButton()
.setCustomId('btn2')
.setLabel('Banner')
.setStyle('PRIMARY');

const button3 = new MessageButton()
.setCustomId('btn3')
.setLabel('User')
.setStyle('PRIMARY');

const button4 = new MessageButton()
.setCustomId('btn4')
.setLabel('Download')
.setStyle('PRIMARY');

const row = new MessageActionRow().addComponents(button1, button2, button3, button4);

const embed = {
color: 0x00000,
title: '**لوحة التحكم**',
thumbnail: {
url: 'https://images-ext-1.discordapp.net/external/f94w4Kx7LEwxrt7Po7bYzflGr20B_til4p1WuxUHGsY/https/res.cloudinary.com/ferv/image/upload/v1698479059/icons/nhzok0alt9fhorojec0b.png?format=webp&quality=lossless&width=473&height=473',
},
description: 'للحصول على افتار شخص أو البنر أو لتحميل مقاطع الفيديو من التيك توك أو الإنستقرام أو اليوتيوب استخدم الأزرار',
};

await interaction.reply({ embeds: [embed], components: [row] });

const collector = interaction.channel.createMessageComponentCollector({
componentType: 'BUTTON',
});

collector.on('collect', async i => {
if (i.customId === 'btn1') {
const modal = new Modal()
.setCustomId('myModal')
.setTitle('My Modal');

const idform = new TextInputComponent()
.setCustomId('idd')
.setLabel("يرجى ادخال ايدي الشخص")


const firstActionRow = new MessageActionRow().addComponents(idform);

modal.addComponents(firstActionRow);
await i.reply({ content: " ", components: [modal] });
}
});
} catch (error) {
console.error(error);
await interaction.reply({ content: 'حدث خطأ أثناء معالجة الطلب.', ephemeral: true });
}
},
};
const { MessageActionRow, MessageButton, Modal, TextInputComponent } = require('discord.js');

module.exports = {
name: 'panel',
description: 'Send Panel',
run: async (client, interaction) => {
try {
const button1 = new MessageButton()
.setCustomId('btn1')
.setLabel('Avatar')
.setStyle('PRIMARY');
const button2 = new MessageButton()
.setCustomId('btn2')
.setLabel('Banner')
.setStyle('PRIMARY');

const button3 = new MessageButton()
.setCustomId('btn3')
.setLabel('User')
.setStyle('PRIMARY');

const button4 = new MessageButton()
.setCustomId('btn4')
.setLabel('Download')
.setStyle('PRIMARY');

const row = new MessageActionRow().addComponents(button1, button2, button3, button4);

const embed = {
color: 0x00000,
title: '**لوحة التحكم**',
thumbnail: {
url: 'https://images-ext-1.discordapp.net/external/f94w4Kx7LEwxrt7Po7bYzflGr20B_til4p1WuxUHGsY/https/res.cloudinary.com/ferv/image/upload/v1698479059/icons/nhzok0alt9fhorojec0b.png?format=webp&quality=lossless&width=473&height=473',
},
description: 'للحصول على افتار شخص أو البنر أو لتحميل مقاطع الفيديو من التيك توك أو الإنستقرام أو اليوتيوب استخدم الأزرار',
};

await interaction.reply({ embeds: [embed], components: [row] });

const collector = interaction.channel.createMessageComponentCollector({
componentType: 'BUTTON',
});

collector.on('collect', async i => {
if (i.customId === 'btn1') {
const modal = new Modal()
.setCustomId('myModal')
.setTitle('My Modal');

const idform = new TextInputComponent()
.setCustomId('idd')
.setLabel("يرجى ادخال ايدي الشخص")


const firstActionRow = new MessageActionRow().addComponents(idform);

modal.addComponents(firstActionRow);
await i.reply({ content: " ", components: [modal] });
}
});
} catch (error) {
console.error(error);
await interaction.reply({ content: 'حدث خطأ أثناء معالجة الطلب.', ephemeral: true });
}
},
};
14 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/luna11mo ago
modals arent components that should error
d.js docs
d.js docs11mo ago
method ButtonInteraction#showModal() Shows a modal component
treble/luna
treble/luna11mo ago
and your textinput is missing a style
Fr³oN || تم النقل الي {6h3h}
Can you give me the true code ?
treble/luna
treble/luna11mo ago
.
Fr³oN || تم النقل الي {6h3h}
/home/runner/avts-generater1/node_modules/discord.js/src/structures/BaseMessageComponent.js:93
throw new TypeError('INVALID_TYPE', 'data.type', 'valid MessageComponentType');
^

TypeError [INVALID_TYPE]: Supplied data.type is not a valid MessageComponentType.
at BaseMessageComponent.create (/home/runner/avts-generater1/node_modules/discord.js/src/structures/BaseMessageComponent.js:93:17)
at /home/runner/avts-generater1/node_modules/discord.js/src/structures/MessagePayload.js:141:79
at Array.map (<anonymous>)
at MessagePayload.resolveData (/home/runner/avts-generater1/node_modules/discord.js/src/structures/MessagePayload.js:141:49)
at ButtonInteraction.reply (/home/runner/avts-generater1/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:101:50)
at InteractionCollector.<anonymous> (/home/runner/avts-generater1/SlashCommands/general/panel.js:58:29)
at InteractionCollector.emit (node:events:525:35)
at InteractionCollector.emit (node:domain:489:12)
at InteractionCollector.handleCollect (/home/runner/avts-generater1/node_modules/discord.js/src/structures/interfaces/Collector.js:110:12) {
[Symbol(code)]: 'INVALID_TYPE'
}

Node.js v18.12.1
/home/runner/avts-generater1/node_modules/discord.js/src/structures/BaseMessageComponent.js:93
throw new TypeError('INVALID_TYPE', 'data.type', 'valid MessageComponentType');
^

TypeError [INVALID_TYPE]: Supplied data.type is not a valid MessageComponentType.
at BaseMessageComponent.create (/home/runner/avts-generater1/node_modules/discord.js/src/structures/BaseMessageComponent.js:93:17)
at /home/runner/avts-generater1/node_modules/discord.js/src/structures/MessagePayload.js:141:79
at Array.map (<anonymous>)
at MessagePayload.resolveData (/home/runner/avts-generater1/node_modules/discord.js/src/structures/MessagePayload.js:141:49)
at ButtonInteraction.reply (/home/runner/avts-generater1/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:101:50)
at InteractionCollector.<anonymous> (/home/runner/avts-generater1/SlashCommands/general/panel.js:58:29)
at InteractionCollector.emit (node:events:525:35)
at InteractionCollector.emit (node:domain:489:12)
at InteractionCollector.handleCollect (/home/runner/avts-generater1/node_modules/discord.js/src/structures/interfaces/Collector.js:110:12) {
[Symbol(code)]: 'INVALID_TYPE'
}

Node.js v18.12.1
this is the error
treble/luna
treble/luna11mo ago
because modals arent components
treble/luna
treble/luna11mo ago
i told you what and how to fix it
treble/luna
treble/luna11mo ago
text inputs are message components modals arent modals can have text inputs
ThePedroo
ThePedroo11mo ago
Good point
Want results from more Discord servers?
Add your server