CMD sending multiple embeds instead of one

Sage

I made a leaderboard command for my discord bot (v13) but it sends multiple embeds with each user's info individually instead of one whole message. I'm not sure how else to structure this so any help is appreciated.

const profileModel = require("../models/profileSchema");
module.exports = {
    name: "leaderboard",
    description: "Checks the leaderboard",
    aliases: ['lb'],
    async execute(client, message, args, cmd, Discord, profileData){

        const lbData = await profileModel.find({}).sort({
            reputation: -1,
        }).limit(5);

        for (let counter = 0; counter < lbData.length; ++counter) {
            const { userID, health = 0 } = lbData[counter]

            const Embed = new Discord.MessageEmbed()
                .setColor('#fffffa')
                .setTitle('Challenge Leaderboard')
                .addFields(
                    { name: '\u200b', value: `**${counter + 1}.** <@${userID}> - ${reputation} reputation\n` })
            message.channel.send({ embeds: [Embed] });
        }
    }
}
abisammy

The reason is the way you send the embed

Inside your for loop you create a new ebed every time and add the fields, where you need to create the embed outisde the for loop, add the field in the for loop and then send the embed

It would look something like:

const Embed = new Discord.MessageEmbed()
    .setColor('#fffffa')
    .setTitle('Challenge Leaderboard')

for (let counter = 0; counter < lbData.length; ++counter) {
    const { userID, health = 0 } = lbData[counter]
    Embed.addField({ name: '\u200b', value: `**${counter + 1}.** <@${userID}> - ${reputation} reputation\n` })            
}

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Sending multiple embeds at once

Multiple typeform embeds on one page

My discord bot is sending multiple messages at once instead of just one

Send multiple embeds in one message with Discord.py

i am sending commands through serial port in python but they are sent multiple times instead of one

One variable instead of multiple

How to grab Cmd-Tab on Macintosh instead of sending to Screen Sharing?

Sending multiple hex in array of bytes instead

multiple ifs in one row of cmd

Discord.py bot not sending embeds properly

Discord Slash Command: Error while sending Embeds

Problem with sending embeds for help command with pages

Mongoid query for embeds_one

Sending multiple record with one call using hiredis

Sending Multiple Dictionary Variables as one in Template

Sending out multiple reports as one email in splunk

Sending multiple DocuSign Template in one email?

Wordpress sending multiple AJAX requests on one click

Sending multiple data in one page Jquery

Django DB Router Sending Table to default DB instead of Correct One

Sending a single reminder email for each address in an array instead of multiple ones

Sending a single reminder email for each address instead of multiple emails

Django-channels : ChatConsumer is sending message to only one user instead of sending it to both users

Using One decorator instead of multiple? "One to many" and "many to one"?

Sending Discord embeds with repeated pattern but different content more optimally

Why isn't embeds index not working when sending a message

guildMemberAdd and guildMemberRemove Embeds not sending anymore (Discord.js)

How to show multiple lines instead of one?

Creating method to use one foreach instead multiple