Property Undefined

//Stuff was here
async execute(interaction, profileData){
const action = interaction.options.getString('action')
const amount = interaction.options.getInteger('amount')
//Embeds were here
if (amount % 1 != 0 || amount <= 0) return interaction.reply({ embeds: [amountWholeNumEmbed], ephemeral: true })
if (action === 'deposit'){
if (amount > profileData.kai) return interaction.reply({ embeds: [notEnoughEmbed], ephemeral: true })
await profileModel.findOneAndUpdate({
userID: interaction.user.id
},
{
$inc: {
kai: -amount,
bank: amount
}
})
return interaction.reply({ embeds: [depCompleteEmbed]})
}
if (action === 'withdraw'){
if (amount > profileData.bank) return interaction.reply({ embeds: [notEnoughEmbed], ephemeral: true })
await profileModel.findOneAndUpdate({
userID: interaction.user.id
},
{
$inc: {
kai: amount,
bank: -amount
}
})
return interaction.reply({ embeds: [withCompleteEmbed]})
}
else {
return interaction.reply({ embeds: [invalidInputEmbed], ephemeral: true })
}
}
}
//Stuff was here
async execute(interaction, profileData){
const action = interaction.options.getString('action')
const amount = interaction.options.getInteger('amount')
//Embeds were here
if (amount % 1 != 0 || amount <= 0) return interaction.reply({ embeds: [amountWholeNumEmbed], ephemeral: true })
if (action === 'deposit'){
if (amount > profileData.kai) return interaction.reply({ embeds: [notEnoughEmbed], ephemeral: true })
await profileModel.findOneAndUpdate({
userID: interaction.user.id
},
{
$inc: {
kai: -amount,
bank: amount
}
})
return interaction.reply({ embeds: [depCompleteEmbed]})
}
if (action === 'withdraw'){
if (amount > profileData.bank) return interaction.reply({ embeds: [notEnoughEmbed], ephemeral: true })
await profileModel.findOneAndUpdate({
userID: interaction.user.id
},
{
$inc: {
kai: amount,
bank: -amount
}
})
return interaction.reply({ embeds: [withCompleteEmbed]})
}
else {
return interaction.reply({ embeds: [invalidInputEmbed], ephemeral: true })
}
}
}
3 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
PAdventures
PAdventuresOP3y ago
Error
TypeError: Cannot read properties of undefined (reading 'kai')
at Object.execute (D:\PA_Admin Backup\Slash Commands\transfer.js:44:38)
at Object.execute (D:\PA_Admin Backup\Events\interactionCreate.js:19:28)
at Client.<anonymous> (D:\PA_Admin Backup\index.js:55:44)
at Client.emit (node:events:520:28)
at InteractionCreateAction.handle (D:\PA_Admin Backup\node_modules\discord.js\src\client\actions\InteractionCreate.js:81:12)
at Object.module.exports [as INTERACTION_CREATE] (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketShard.js:481:22)
at WebSocketShard.onMessage (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketShard.js:321:10)
at WebSocket.onMessage (D:\PA_Admin Backup\node_modules\ws\lib\event-target.js:199:18)
node:events:498
throw er; // Unhandled 'error' event
^

TypeError: "" is not a function
at Object.execute (D:\PA_Admin Backup\Events\interactionCreate.js:25:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:381:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21)
TypeError: Cannot read properties of undefined (reading 'kai')
at Object.execute (D:\PA_Admin Backup\Slash Commands\transfer.js:44:38)
at Object.execute (D:\PA_Admin Backup\Events\interactionCreate.js:19:28)
at Client.<anonymous> (D:\PA_Admin Backup\index.js:55:44)
at Client.emit (node:events:520:28)
at InteractionCreateAction.handle (D:\PA_Admin Backup\node_modules\discord.js\src\client\actions\InteractionCreate.js:81:12)
at Object.module.exports [as INTERACTION_CREATE] (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketShard.js:481:22)
at WebSocketShard.onMessage (D:\PA_Admin Backup\node_modules\discord.js\src\client\websocket\WebSocketShard.js:321:10)
at WebSocket.onMessage (D:\PA_Admin Backup\node_modules\ws\lib\event-target.js:199:18)
node:events:498
throw er; // Unhandled 'error' event
^

TypeError: "" is not a function
at Object.execute (D:\PA_Admin Backup\Events\interactionCreate.js:25:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:381:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21)
chewie
chewie3y ago
you didnt pass profileData to the function not djs related #useful-servers
Want results from more Discord servers?
Add your server