Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!