#Hm okay I did ```js

1 messages · Page 1 of 1 (latest)

broken rampart
#
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)

raven spear
#

so the code for detecting modalSubmits isnt going to work

broken rampart
#

Do i need to put the modal check above it?

raven spear
#
if(interaction.isModalSubmit()){
//ur code
}
if(!interaction.isCommand()) return
broken rampart
#

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

raven spear
broken rampart
#

OH

#

i gotchu

valid oakBOT
#

Tag suggestion for @broken rampart:
To share long code snippets use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks.

broken rampart
#

@raven spear what part sets the modal name, is it the CustomId?

raven spear
#

if ur trying to check if its the right one, id use customId

broken rampart
#

so interaction.showModal(name) and then the name is what i put for

        const modal = new ModalBuilder()
            .setCustomId('loa')
```?
#

so loa

raven spear
#

yea loa would be what u check

broken rampart
#

awesome :)

raven spear
#

interaction.customId is how ud access it in ur event

broken rampart
#

under InteractionCreate?

raven spear
#

yea

broken rampart
#

I'm still getting

TypeError: Cannot read properties of undefined (reading 'getTextInputValue')

raven spear
#

show the code where that originates from

raven spear
#

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

broken rampart
#

when i run the command

raven spear
raven spear
#

show ur interactionCreate event code

raven spear
#

put that code in if(interaction.isModalSubmit(){
}

#

and make sure that if statement is above ur command checker

broken rampart
#

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

raven spear
#

yeah like that

broken rampart
#

Hm i did that and still got the error

raven spear
#

though dont put interaction.showModal as that wont work there

#

did u save ur files

broken rampart
#

ya

raven spear
#

can i see the full error

#

u can just copy paste it here or take a screenshot

broken rampart
#

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)

raven spear
broken rampart
#

Huh?

#

It's been removed and saved c_cry

raven spear
#

well it says on line 39 of that file theres a line trying to getTextInputValue

broken rampart
#

line 39 in my loa.js is

      interaction.reply({
#

D:

raven spear
#

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

broken rampart
#

yep 100% sure

raven spear
#

did u restart the bot

broken rampart
#

im using nodemon so it restarts on save

#

gunna restart my VSCode

broken rampart
#

but

#

it didn't pop up a menu when i ran the command, it just said LOA submitted?!

raven spear
broken rampart
#

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?

raven spear
#

showModal counts as a reply

#

so ull have to use interaction.followUp

broken rampart
#

when submitting?

#

i'm so sorry haha

raven spear
# broken rampart when submitting?

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

broken rampart
#

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?

raven spear
broken rampart
raven spear
broken rampart
raven spear
broken rampart
#

TypeError [ModalSubmitInteractionFieldNotFound]: Required field with custom id "nameInput" not found.

#

now this

#

omlll

raven spear
#

getTextInputValue('name')

broken rampart
broken rampart
#
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"

raven spear
broken rampart
raven spear
broken rampart
raven spear
broken rampart
# raven spear doesnt look like it thinks its a function. why dont u create the function outsid...

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

raven spear
#

just leave this bit

broken rampart
#

huh am confused