Modal submit, 2d time, crashes app

const { SlashCommandBuilder, ActionRowBuilder, Events, ModalBuilder, TextInputBuilder, TextInputStyle, InteractionType } = require('discord.js');
const db = require('../../models');
const Customer = db.customer;
const config = require('../../Configs/config.js');

module.exports = {
data: {
name: "register",
description: "Register as a customer or supplier.",
dm_permissions: "0",
},
async execute(interaction, client) {
const modal = new ModalBuilder()
.setCustomId('registerModal')
.setTitle('Register as a Customer & Supplier!');

const characterName = new TextInputBuilder()
.setCustomId('characterName')
.setLabel("What's your in-game character name?")
.setPlaceholder('Enter in-game character name')
.setStyle(TextInputStyle.Short);

const guildName = new TextInputBuilder()
.setCustomId('guildName')
.setLabel("What's your in-game guild name?")
.setPlaceholder('Enter in-game guild name')
.setStyle(TextInputStyle.Short);

const customerType = new TextInputBuilder()
.setCustomId('customerType')
.setLabel("What role do you wish to fulfill?")
.setPlaceholder('Supplier / Buyer / Both')
.setStyle(TextInputStyle.Short)
.setRequired(true);

const comment = new TextInputBuilder()
.setCustomId('comment')
.setLabel("Do you want to add something else?")
.setStyle(TextInputStyle.Paragraph)
.setRequired(false);

const characterActionRow = new ActionRowBuilder().addComponents(characterName);
const guildActionRow = new ActionRowBuilder().addComponents(guildName);
const customerActionRow = new ActionRowBuilder().addComponents(customerType);
const commentActionRow = new ActionRowBuilder().addComponents(comment);

modal.addComponents(characterActionRow, guildActionRow, customerActionRow, commentActionRow);

await interaction.showModal(modal)
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isModalSubmit()) return;
if (interaction.customId === 'registerModal') {
const guild = await interaction.client.guilds.fetch(config.GUILD_ID);
const channel = await guild.channels.fetch(config[`REGISTER_FEED`]);
const customer = await Customer.findOne({ where: { discordId: interaction.user.id } });

if (!customer) {
await Customer.create({
discordName: interaction.user.tag,
discordId: interaction.user.id,
gameName: interaction.fields.getTextInputValue('characterName'),
gameGuild: interaction.fields.getTextInputValue('guildName'),
userType: interaction.fields.getTextInputValue('customerType'),
comment: interaction.fields.getTextInputValue('comment'),
});
await interaction.reply({ content: 'Your submission was received successfully!', ephemeral: true});
await channel.send({ content: `<@${interaction.user.id}> just registered!` });
} else {
await interaction.deferReply({ content: 'You are already registered!', ephemeral: true});
}
}
});
}
}
const { SlashCommandBuilder, ActionRowBuilder, Events, ModalBuilder, TextInputBuilder, TextInputStyle, InteractionType } = require('discord.js');
const db = require('../../models');
const Customer = db.customer;
const config = require('../../Configs/config.js');

module.exports = {
data: {
name: "register",
description: "Register as a customer or supplier.",
dm_permissions: "0",
},
async execute(interaction, client) {
const modal = new ModalBuilder()
.setCustomId('registerModal')
.setTitle('Register as a Customer & Supplier!');

const characterName = new TextInputBuilder()
.setCustomId('characterName')
.setLabel("What's your in-game character name?")
.setPlaceholder('Enter in-game character name')
.setStyle(TextInputStyle.Short);

const guildName = new TextInputBuilder()
.setCustomId('guildName')
.setLabel("What's your in-game guild name?")
.setPlaceholder('Enter in-game guild name')
.setStyle(TextInputStyle.Short);

const customerType = new TextInputBuilder()
.setCustomId('customerType')
.setLabel("What role do you wish to fulfill?")
.setPlaceholder('Supplier / Buyer / Both')
.setStyle(TextInputStyle.Short)
.setRequired(true);

const comment = new TextInputBuilder()
.setCustomId('comment')
.setLabel("Do you want to add something else?")
.setStyle(TextInputStyle.Paragraph)
.setRequired(false);

const characterActionRow = new ActionRowBuilder().addComponents(characterName);
const guildActionRow = new ActionRowBuilder().addComponents(guildName);
const customerActionRow = new ActionRowBuilder().addComponents(customerType);
const commentActionRow = new ActionRowBuilder().addComponents(comment);

modal.addComponents(characterActionRow, guildActionRow, customerActionRow, commentActionRow);

await interaction.showModal(modal)
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isModalSubmit()) return;
if (interaction.customId === 'registerModal') {
const guild = await interaction.client.guilds.fetch(config.GUILD_ID);
const channel = await guild.channels.fetch(config[`REGISTER_FEED`]);
const customer = await Customer.findOne({ where: { discordId: interaction.user.id } });

if (!customer) {
await Customer.create({
discordName: interaction.user.tag,
discordId: interaction.user.id,
gameName: interaction.fields.getTextInputValue('characterName'),
gameGuild: interaction.fields.getTextInputValue('guildName'),
userType: interaction.fields.getTextInputValue('customerType'),
comment: interaction.fields.getTextInputValue('comment'),
});
await interaction.reply({ content: 'Your submission was received successfully!', ephemeral: true});
await channel.send({ content: `<@${interaction.user.id}> just registered!` });
} else {
await interaction.deferReply({ content: 'You are already registered!', ephemeral: true});
}
}
});
}
}
This is my code for a modal for a game i'm building in discord. The modal can be submitted just fine, but i try to submit it again after, it will crash my bot.
rawError: { message: 'Unknown interaction', code: 10062 }
rawError: { message: 'Unknown interaction', code: 10062 }
Any help? ❤️
7 Replies
d.js toolkit
d.js toolkit15mo 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! - Marked as resolved by OP
treble/luna
treble/luna15mo ago
dont nest your listeners Eiter use priper event handling, like explained in the guide Or use collectors
Xirez
XirezOP15mo ago
Hm, okey, do you have a link to said guide?
treble/luna
treble/luna15mo ago
also thats not how you use deferreply
d.js docs
d.js docs15mo ago
guide Popular Topics: Collectors read more
treble/luna
treble/luna15mo ago
I recommend checking out the full guide
Xirez
XirezOP15mo ago
I'll do that, thank you so much for the fast response! Appreciate it wolvinny! ❤️
Want results from more Discord servers?
Add your server