Skip to content

discordjs v13 – subtract the variable

The code doesn’t work when it subtract the variable (enemy’s health)

This is my code

 if (message.content === ".battle") {
//hidden code....

let damage = Math.floor(Math.random() * 10)
let user =

    let embed = new Discord.MessageEmbed()
    .setTitle(`${user.username}'s battle`)
**${user.username}'s Stats**
Health: ${player_health}
Mana: ${player_mana}
Power: ${power}
Frist Skill: ${a1}
Second Skill: ${a2}
Third Skill: ${a3}

//enemy embed
let ene_health = 100
let ene_xp = 10

       let embed1 = new Discord.MessageEmbed()
.setTitle(`${user.username}'s battle`)
**Enemy's Stats**
Health: ${ene_health}
Mana: ${ene_mana}

        const row = new MessageActionRow()
                new MessageButton()
                    .setLabel(`Use: ${power}`)
    //hidden code......

    await message.reply({ content: "You have 1 minute to choose the skills", embeds: [embed, embed1], components: [row] });
    const filter = i => i.customId === 'primary' && === `${}`;

const collector ={ filter, time: 60000 });

    collector.on('collect', async i => {
    if (i.customId === 'primary') {
        await i.deferUpdate();
        await wait(4000);
        await i.editReply({ content: `You've use ${power} power and you deal the ${damage} Dmg.`, components: [] }) 
//there the problem
damage - ene_health

collector.on('end', collected => console.log(`Collected ${collected.size} button`));

I wonder at the damage - ene_health why it doesn’t subtract the enemy’s health

I am using discord.js v13 and quickdb

it must subtract the enemy's health but it won't subtract


damage - ene_health

isn’t doing anything. In your case you have to CHANGE the damage variable.

damage = damage - ene_health

or even better, use the Substract assignment :

damage -= ene_health