#Hm okay I did ```js
1 messages · Page 1 of 1 (latest)
bot.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return
if (!interaction.isModalSubmit()) return;
const command = bot.commands.get(interaction.commandName)
if (!command) return
try {
await command.execute(interaction)
} catch (err) {
console.error(err)
await interaction.reply({
content: 'An error occured while executing this command',
ephemeral: true
})
}
// console.log(interaction)
})
@raven spear
I'm using it for modals (obviously haha)
well ur checking first if its a command and if it isnt, its returning
so the code for detecting modalSubmits isnt going to work
Do i need to put the modal check above it?
if(interaction.isModalSubmit()){
//ur code
}
if(!interaction.isCommand()) return
Hm what code goes inside the isModalSubmit one? I'm just learning Modals now
How do i send my code for other things? it's too big to show here haha
i'll show you what i'm doing
interaction.showModal(yourmodalhere)
@raven spear what part sets the modal name, is it the CustomId?
there isnt a name property for a modal, theres a Title and CustomId
if ur trying to check if its the right one, id use customId
so interaction.showModal(name) and then the name is what i put for
const modal = new ModalBuilder()
.setCustomId('loa')
```?
so loa
yea loa would be what u check
awesome :)
interaction.customId is how ud access it in ur event
under InteractionCreate?
yea
I'm still getting
TypeError: Cannot read properties of undefined (reading 'getTextInputValue')
show the code where that originates from
thats for where u show ur modal
can u show us the interactionCreate event
oh nvm i see
basically this code needs to go in the interactionCreate event
where u setup the .isModalSubmit
hm, still getting
TypeError: Cannot read properties of undefined (reading 'getTextInputValue')
when i run the command
did u delete this from ur cmd file and move it to the right place?
yeah
show ur interactionCreate event code
you removed your code for checking if its a modal!
put that code in if(interaction.isModalSubmit(){
}
and make sure that if statement is above ur command checker
Oh that if statement goes inside of the isModalSubmit checker?
if(interaction.isModalSubmit()) {
if(interaction.customId === 'loa') {
const name = interaction.fields.getTextInputValue('nameInput');
const reason = interaction.fields.getTextInputValue('reasonInput');
await interaction.showModal(modal)
const embed = new Discord.MessageEmbed()
.setTitle('Leave of Absence')
.setDescription('**New Form Submitted**')
.addField('Reason', '```' + reason + '```')
// .addField('Length', '```' + interaction.values[1] + '```')
.setFooter(`Submitted by ${name}`)
.setTimestamp()
.setColor(config.colors.main)
const channel = await bot.channels.fetch('1028291276925325483')
channel.send({
embeds: [embed]
})
}
}
``` Like this?
tf
yeah like that
Hm i did that and still got the error
ya
TypeError: Cannot read properties of undefined (reading 'getTextInputValue')
at Object.execute (E:\Programming\JS\CNC\commands\loa.js:39:41)
at Client.<anonymous> (E:\Programming\JS\CNC\index.js:110:19)
at Client.emit (node:events:527:28)
at InteractionCreateAction.handle (E:\Programming\JS\CNC\node_modules\discord.js\src\client\actions\InteractionCreate.js:81:12)
at Object.module.exports [as INTERACTION_CREATE] (E:\Programming\JS\CNC\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (E:\Programming\JS\CNC\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (E:\Programming\JS\CNC\node_modules\discord.js\src\client\websocket\WebSocketShard.js:481:22)
at WebSocketShard.onMessage (E:\Programming\JS\CNC\node_modules\discord.js\src\client\websocket\WebSocketShard.js:321:10)
at WebSocket.onMessage (E:\Programming\JS\CNC\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:527:28)
that means u havent removed this code from your command file yet or that file hasnt been saved
well it says on line 39 of that file theres a line trying to getTextInputValue
the error disagrees, are u 100% sure u saved the file? you may have saved a different one
if u are using vscode u can go to file -> save all just in case
yep 100% sure
did u restart the bot
Okay so that worked
but
it didn't pop up a menu when i ran the command, it just said LOA submitted?!
u need to use interaction.showModal somewhere above interaction.reply
E:\Programming\JS\CNC\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:102
if (this.deferred || this.replied) throw new Error(ErrorCodes.InteractionAlreadyReplied);
^
Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
at ChatInputCommandInteraction.reply (E:\Programming\JS\CNC\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:102:46)
at Object.execute (E:\Programming\JS\CNC\commands\loa.js:41:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Client.<anonymous> (E:\Programming\JS\CNC\index.js:108:5) {
code: 'InteractionAlreadyReplied'
}
It worked, but got these errors when the menu popped up, though i've not submitted a reply already?
ah sorry i forgot
showModal counts as a reply
so ull have to use interaction.followUp
in your interactionCreate event, u need to respond to the modal interaction. If you do not want to you can use interaction.deferUpdate(), but it is reccomended u inform the user the interaction was successful if they cant see teh channel the embed was sent to
In loa.js
It responds with: ```js
interaction.followUp({
content: 'Leave of absence request submitted.',
ephemeral: true
})
but in interactionCreate, i'm doing:
const channel = await bot.channels.fetch('1028291276925325483')
channel.send({
embeds: [embed]
})
``` which also isn't working?
maybe that's what causing it?
well channel.send doesnt count as responding to an interaction, so u have to respond to the modal interaction in interactionCreate as well
with interaction.reply or await interaction.showModal(modal)?
showModal shows another modal, so use interaction.reply or any other equivelents
STILL getting that error
all this code needs to be above the if(interaction.isCommand) statement
o shoot yeah forgot that
TypeError [ModalSubmitInteractionFieldNotFound]: Required field with custom id "nameInput" not found.
now this
omlll
the getters go off of these
getTextInputValue('name')
gotcha! Just trying to fix an unrelated error rn, bare with haha
I'm using a util.js to build embeds, but can i not call for them inside of the interaction.customId if statement?
const { EmbedBuilder } = require('discord.js')
const config = require('../config.json')
const types = {
'error': config.colors.failed,
'success': config.colors.success,
'main': config.colors.main,
}
module.exports = {
EmbedMe(type, interaction) {
if (!type) throw new Error('Type is required')
if (!types[type]) throw new Error('Invalid type')
return new EmbedBuilder()
.setColor(types[type])
.setTimestamp()
.setImage('https://imgur.com/B4vKVhu.png')
.setFooter({
text: `Submitted by ${interaction.user.tag}`,
});
}
}
^ in my utils.js
const embed = EmbedMe('main', interaction)
.setTitle('Leave of Absence')
.setDescription('**New Form Submitted**')
.addField('Reason', reason)
.setFooter(`Submitted by ${name}`)
.setTimestamp()
.setColor(config.colors.main)
const channel = await bot.channels.fetch('1028291276925325483')
channel.send({
embeds: [embed]
})
What i'm trying to do, but getting "TypeError: EmbedMe is not a function"
did u import the function into whatever file ur trying to use it in?
Yeah it's at the very top of my index.js
can i see the import
doesnt look like it thinks its a function. why dont u create the function outside the module exports and pass
module.exports = {
EmbedMe,
}
in ur embed.js file
like
const { EmbedBuilder } = require('discord.js')
const config = require('../config.json')
const types = {
'error': config.colors.failed,
'success': config.colors.success,
'main': config.colors.main,
}
module.exports = {
EmbedMe(type, interaction) {
if (!type) throw new Error('Type is required')
if (!types[type]) throw new Error('Invalid type')
return new EmbedBuilder()
.setColor(types[type])
.setTimestamp()
.setImage('https://imgur.com/B4vKVhu.png')
.setFooter({
text: `Submitted by ${interaction.user.tag}`,
});
}
}
module.exports = {
EmbedMe,
}
nvm that didn't work
dont rap the actual EmbedMe function in a module.exports
just leave this bit
huh am confused
