'hello I am getting an error that shows up in discord modal it tells Something went wrong. try again discord.js
Hello I made a mail command which would take message from modal and send it to a mentioned user but it gives this error in modal window and does not log anything in console

const { Permissions } = require('discord.js');
const { Modal, TextInputComponent, showModal } = require('discord-modals')
const { Formatters } = require('discord.js');
module.exports.run = async (Client, message, args, prefix) => {
let member = message.mentions.members.first();
if(!message.content.includes(member)) {
embed = new MessageEmbed()
.setColor('RED')
.setTitle('Whome shd I send this mail to bruh')
.setDescription('Please mention the user whome you want to deliver the message')
await message.reply({embeds:[embed]})
}
else {
msg = new MessageEmbed()
.setColor('GREEN')
.setTitle('its time to type your message to your friend')
.setDescription('Please type your subject and message as you do while composing a normal mail using gmail just click the button and fill the subject and the message in their respective fields')
const row = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId('compose')
.setLabel('Fill up info and compose')
.setEmoji('📧')
.setStyle('SECONDARY')
);
const msg = await message.reply({embeds:[msg],components: [row]});
//defining intput text fields
let textinput = new TextInputComponent()
.setCustomId('textinput-customid')
.setLabel('Subject')
.setStyle('SHORT')
.setMinLength('1')
.setMaxLength('200')
.setPlaceholder('type your Subject here it can be anything in less than 200 words')
.setRequired(true)
let textinputl = new TextInputComponent()
.setCustomId('textinput-customidl')
.setLabel('Message')
.setStyle('LONG')
.setMinLength('1')
.setMaxLength('4000')
.setPlaceholder('type your message here it can be anything in less than 4000 words')
.setRequired(true)
//main modal
const modal = new Modal() // We create a Modal
.setCustomId('modal-customid')
.setTitle('Compose a mail')
.addComponents([ textinput, textinputl ])
Client.on('interactionCreate', (interaction) => {
if(interaction.isButton) {
if(interaction.customId === 'compose'){
showModal(modal, {
client: Client,
interaction: interaction
})
}
}
})
Client.on('modalSubmit', async (modal) => {
if(modal.customId === 'modal-customid'){
const subjectresponse = modal.getTextInputValue('textinput-customid')
const messageresponse = modal.getTextInputValue('textinput-customidl')
modal.followUp({ content: 'Done message delivered.' + Formatters.codeBlock('markdown', firstResponse), ephemeral: true })
const embed = new MessageEmbed()
.setTitle('You have a new mail')
.setDescription(`${message.author.username} has sent you an email`)
.addField('Subject:', `${subjectresponse}`, false)
.addField('Message:', `${messageresponse}`, false)
await message.reply({embeds:[embed]});
}
})
}
}
module.exports.help = {
name: 'mail',
aliases: []
}
this is the code please check it out and tell what is the error on the git error page of this people were asking about it but I dint understand that
Solution 1:[1]
Have to make a lot of code changes, here is what the final result was below, basically the issue was that there were a lot of variances in the code and how the code was handled. Needed to add checks to the code to help it move along. Added the member id to the embed to help the bot get that id when it needed it later.
command.js file
const mentionedMember = message.mentions.members.first();
if (!mentionedMember || mentionedMember.user.bot) {
const embed = new MessageEmbed()
.setColor('RED')
.setTitle('Whom should I send this mail to bruh')
.setDescription('Please mention the user whom you want to deliver the message, no bots');
message.reply({
embeds: [embed],
});
setTimeout(() => {
message.delete();
}, 100);
} else {
const rickrollmsg = new MessageEmbed()
.setColor('GREEN')
.setTitle('its time to type your message to your friend')
.setDescription('Please type your subject and message as you do while composing a normal mail using gmail just click the button and fill the subject and the message in their respective fields')
.setFooter({
text: mentionedMember.id,
});
const row = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId('compose')
.setLabel('Fill up info and compose')
.setEmoji('?')
.setStyle('SECONDARY'),
);
message.reply({
embeds: [rickrollmsg],
components: [row],
});
setTimeout(() => {
message.delete();
}, 100);
}
interactionCreate button code
const textinput = new TextInputComponent()
.setCustomId('rickmail-subject')
.setLabel('Subject')
.setStyle('SHORT')
.setMinLength('1')
.setMaxLength('200')
.setPlaceholder('type your Subject here it can be anything in less than 200 words')
.setRequired(true);
const textinputl = new TextInputComponent()
.setCustomId('rickmail-message')
.setLabel('Message')
.setStyle('LONG')
.setMinLength('1')
.setMaxLength('4000')
.setPlaceholder('type your message here it can be anything in less than 4000 words')
.setRequired(true);
const modal = new Modal()
.setCustomId('rickmail')
.setTitle('Compose a rickmail')
.addComponents([textinput, textinputl]);
showModal(modal, {
client: client,
interaction: inter,
});
modalSubmit listener
const member = modal.guild.members.cache.get(modal.message.embeds[0].footer.text);
const subject = modal.getTextInputValue('rickmail-subject');
const message = modal.getTextInputValue('rickmail-message');
const embed = new MessageEmbed()
.setColor('RANDOM')
.setTitle(`${subject}`)
.setDescription(`${message}`)
.setImage('https://www.icegif.com/wp-content/uploads/rick-roll-icegif-5.gif')
.setFooter({
text: `Message Received ${new Date().toLocaleString()}`,
});
modal.message.delete();
member.send({
embeds: [embed],
});
return modal.followUp({
content: 'Rickmail sent',
ephemeral: true,
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
