Search code examples
botsdiscorddiscord.jsembed

Trying to show player names in a column in discord.js embed bot


Hey guys im trying to figure out how make an embed in a bot that basically shows a teams roster, but I can't figure out how to make the team players names in a column. I tried putting it in .addfield but it didn't work. Heres an example of what I'm trying to do 1

    case 'roster':
        const roster = new Discord.MessageEmbed()
        .setTitle('FinalSpark')
        .setDescription('Rank: 3 | Region: EU | League: CCL')
        .setURL('https://club.mpcleague.com')
        .setFooter('bot made by alex :D')
        .addField('Roster')
        message.channel.send(roster);
        break;

Solution

  • Looks like that embed uses two fields, the second one having a blank title

    The way you should go about this is first getting your roster list into an array, and then splitting the array in half:

    //your roster array
    const roster = [];
    //round up so the first row always either has equal or more items
    //use Math.floor() if you want the opposite
    const midIndex = Math.ceil(roster.length / 2);
    
    const firstRow = roster.slice(0, midIndex);
    const secondRow = roster.slice(midIndex);
    
    const embed = new Discord.MessageEmbed()
        .setTitle('FinalSpark')
        .setDescription('Rank: 3 | Region: EU | League: CCL')
        .setURL('https://club.mpcleague.com')
        .addField("Roster", firstRow.join("\n"), true);
    
    if (secondRow.length) { 
        // \u200b is what makes the invisble effect, you can have \u200b
        // for both the key and value which would essentially make a blank line
        embed.addField("\u200b", secondRow.join("\n"), true);
    }
    
    message.channel.send(embed);
    

    That would be inside of the case statement of course.