X525
DIAdiscord.js - Imagine an app
•Created by X525 on 1/30/2024 in #djs-questions
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!`)
}
},
Cannot access 'tokens' before initialization
at const { tokens } = profileData;
2 replies