Search code examples
javascriptnode.jsdiscorddiscord.jsembed

Multiple lines in one value of an embed (discord.js)


I am trying to create for my needs an embed with my discord.js bot. Unfortuanlty I can't figure out how to do multiple lines in one value field. I tried with the new line character \n, but this was awful, because my lines were getting really long and unreadable, and you can't just start a new coding line in javascript, because semicolons are optional.

Does someone have an idea? Here is a template:

const embed = new Discord.MessageEmbed()
      .setTitle("EVERY ROLE EXPLAINED")
      .setColor(color)
      .addFields(
          {name: "__Column 1__", value: "line 1\n line 2\line three", inline: true},
          {name: "__Column 2__", value: "line 1\n line 2\line three", inline: true}
      )

Solution

  • You can use the backtick (`) key

    // with backtick
    console.log(`line 1
    line 2
    line 3`)
    
    // without backtick
    console.log('line 1\nline 2\nline 3')
    
    // same results 👍


    Another idea would be to concatenate multiple strings in a new line.

    // with concatenation
    console.log('line 1\n' +
    'line 2\n' +
    'line 3\n')
    
    // without concatenation
    console.log('line 1\nline 2\nline 3')
    
    // same results 👍