Need help with error

async execute(interaction, profileData) {
const { id } = interaction.user;
const { tokens } = profileData;

await interaction.deferReply();

const randomNum = Math.round(Math.random());
const result = randomNum ? "Heads" : "Tails";
const choice = interaction.options.getString("choice")
const amount = interaction.options.getInteger("amount")


if (amount >= tokens) {
if(choice === result) {
await profileModel.findOneAndUpdate(
{
userId: id
},
{
$inc: {
tokens: amount * 2
}
}
);

await interaction.editReply(`Winner! You won ${amount*2} coins with **${choice}**`)
} else {
await interaction.editReply(`You lost! The coin landed on **${result}**`)
}
} else {
await interaction.editReply(`You dont have enough Tokens!`)
}


},
async execute(interaction, profileData) {
const { id } = interaction.user;
const { tokens } = profileData;

await interaction.deferReply();

const randomNum = Math.round(Math.random());
const result = randomNum ? "Heads" : "Tails";
const choice = interaction.options.getString("choice")
const amount = interaction.options.getInteger("amount")


if (amount >= tokens) {
if(choice === result) {
await profileModel.findOneAndUpdate(
{
userId: id
},
{
$inc: {
tokens: amount * 2
}
}
);

await interaction.editReply(`Winner! You won ${amount*2} coins with **${choice}**`)
} else {
await interaction.editReply(`You lost! The coin landed on **${result}**`)
}
} else {
await interaction.editReply(`You dont have enough Tokens!`)
}


},
why am i getting the error Cannot access 'tokens' before initialization at const { tokens } = profileData;
1 Reply
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Want results from more Discord servers?
Add your server