- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- 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!
✅Marked as resolved by OP
#Deprecated form creation functions on discordr.js
22 messages · Page 1 of 1 (latest)
you cant show a modal from a message event first of all
it needs to be shown from an interaction
second, whats your djs version
third: that error doesn’t come from that code
Oh, I'll take another look.
my version is: [email protected]
Complete code without introduction and token:
client.on('messageCreate', async (message) => {
if (message.content === '!form') {
// Vytvoření modalu s textovým a výběrovým polem
const modal = new ModalBuilder()
.setCustomId('formModal')
.setTitle('Formulář pro výběr')
.addComponents(
// Textové pole
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('textInput')
.setLabel('Napiš svůj text')
.setStyle(TextInputStyle.Paragraph)
.setPlaceholder('Napiš něco...')
.setRequired(true)
),
// První výběrové pole
new ActionRowBuilder().addComponents(
new StringSelectMenuBuilder()
.setCustomId('selectMenu1')
.setPlaceholder('Vyber jednu možnost')
.addOptions(
{ label: 'Možnost 1', value: 'option1' },
{ label: 'Možnost 2', value: 'option2' },
{ label: 'Možnost 3', value: 'option3' }
)
.setRequired(true)
),
// Druhé výběrové pole
new ActionRowBuilder().addComponents(
new StringSelectMenuBuilder()
.setCustomId('selectMenu2')
.setPlaceholder('Vyber další možnost')
.addOptions(
{ label: 'Volba A', value: 'choiceA' },
{ label: 'Volba B', value: 'choiceB' },
{ label: 'Volba C', value: 'choiceC' }
)
.setRequired(true)
)
);
await message.reply({ content: 'Klikni pro vyplnění formuláře!', ephemeral: true });
await message.channel.send({ content: 'Klikni na tlačítko pro formulář', components: [modal] });
}
});
// Obsluha interakcí
client.on('interactionCreate', async (interaction) => {
if (interaction.type === InteractionType.ModalSubmit) {
const textInput = interaction.fields.getTextInputValue('textInput');
const selectedOption1 = interaction.fields.getSelectMenuValue('selectMenu1');
const selectedOption2 = interaction.fields.getSelectMenuValue('selectMenu2');
await interaction.reply({
content: `Formulář odeslán! \n\nText: ${textInput} \nVybraný první výběr: ${selectedOption1} \nVybraný druhý výběr: ${selectedOption2}`,
ephemeral: true
});
}
});
first of all dont nest your listeners
and as i told you, modals cannot be shown from a message, nor is that code correct
where did you get that code from
because modals do not have selec tmenus
yeah no
dont ask ai to write code because this is the result
use the guide
and first of all learn the basics of js if you havent already
and where can I find a guide?
Thank you, go study.
Home: Introduction