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

93
Vistas
embed adding the same line multiple times

I'm currently working on a command show a user's profile using and embed but every time the command gets used the text gets added again. so if you use the command twice you see the text twice and so on. I've tried to find a solution for about an hour but I can't find anything. I've also tried to rewrite the code multiple times and I currently have this

const { discord, MessageEmbed } = require('discord.js');
const embed = new MessageEmbed();
const users = require('../users.json');
const stand = require('../standsInfo.json');
module.exports = {
   name: 'profile',
   description: 'show the users profile',

   execute(message, args) {
    var user = message.author;
    var xpNeeded = (users[user.id].level+(users[user.id].level+1))*45;
    embed.setTitle(`${user.username}'s profile`);
    embed.setThumbnail(user.displayAvatarURL());
    embed.addField('level', `${users[user.id].level}`);
    embed.addField('experience', `${users[user.id].xp}/${xpNeeded}`); 

    message.channel.send({embeds: [embed] });
 }
}

edit: so. I just realized what was wrong I used addField instead of setField

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

0

Move const embed = new MessageEmbed(); to inside the execute scope. Otherwise you will keep editing the same embed and sending again, with added fields

const { discord, MessageEmbed } = require('discord.js');
const users = require('../users.json');
const stand = require('../standsInfo.json');
module.exports = {
   name: 'profile',
   description: 'show the users profile',

   execute(message, args) {
    var user = message.author;
    var xpNeeded = (users[user.id].level+(users[user.id].level+1))*45;
    const embed = new MessageEmbed();
    embed.setTitle(`${user.username}'s profile`);
    embed.setThumbnail(user.displayAvatarURL());
    embed.addField('level', `${users[user.id].level}`);
    embed.addField('experience', `${users[user.id].xp}/${xpNeeded}`); 

    message.channel.send({embeds: [embed] });
 }
}
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