Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
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 = message.author

    let embed = new Discord.MessageEmbed()
    .setTitle(`${user.username}'s battle`)
    .setColor("GREEN")
    .setDescription(`
**${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`)
    .setDescription(`
**Enemy's Stats**
Health: ${ene_health}
Mana: ${ene_mana}
`)

        const row = new MessageActionRow()
            .addComponents(
                new MessageButton()
                    .setCustomId('primary')
                    .setLabel(`Use: ${power}`)
                    .setStyle('PRIMARY'),
            );
    //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' && i.user.id === `${message.author.id}`;

const collector = message.channel.createMessageComponentCollector({ 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

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda