Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

96
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda