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

https://sourceb.in/GVG52tboOv this is my JavaScript file. I want when I send modal it will send value of textinput into console just for test, but I`m having an error: TypeError: Cannot read properties of undefined (reading 'getTextInputValue')
11 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
edocsil
edocsil2y ago
const ticket_modal_nickname1 = await interaction.fields.getTextInputValue('ticket_modal_nickname');
const ticket_modal_nickname1 = await interaction.fields.getTextInputValue('ticket_modal_nickname');
Some interaction types do not have a .fields property so interaction.fields may be undefined. Use type guards so that this only gets checked for modal submit interactions Also it doesn't need to be awaited because it's not a Promise
tenfy
tenfy2y ago
What should I replace this part with? Thank you for help.
edocsil
edocsil2y ago
You don't have to replace it, just don't try to use it unless you check whether the interaction is a modal first
tenfy
tenfy2y ago
so i have to check if the interaction is modal and then it should work?
edocsil
edocsil2y ago
Yes it will work if the interaction is a modal
tenfy
tenfy2y ago
i should check it with: if (interaction.isModalSubmit()) {}?
edocsil
edocsil2y ago
Yep, that's the correct type guard
tenfy
tenfy2y ago
I tried:
if (interaction.isModalSubmit()) {
console.log("test");
}
if (interaction.isModalSubmit()) {
console.log("test");
}
but it doesn't logs test in console
edocsil
edocsil2y ago
Then the code isn't running or the interaction isn't a modal
tenfy
tenfy2y ago
i tried it in my interactionCreate file and now it logs "test" in console so i think i should do it thru another file