Search code examples
javascriptnode.jsdiscorddiscord.js

DiscordJS v14 | Displaying user input in an embed in a new line with \n


I am trying to use user input in a Discord embed and display it (from a slash command). I am able to get the user input and generate the embed, but the format of the text is not looking good. Specifically, when I set the "Content" of the embed using .setDescription(content), the text appears in an unappealing format.

I have tried using the \n character to create new lines, but it is not working. However, I am able to make text bold using **.

Can you help me understand how I can create new lines in the embed's content?

How it looks

I get the content directly from the user input:

let content = interaction.options.getString("content")

Solution

  • If you receive the content using interaction.options.getString("content"), that \n is no longer the newline character, more like an escaped backslash "\\" followed by the letter "n".

    It means you can replace those with a newline character:

    let content = interaction.options
      .getString('content')
      .replaceAll('\\n', '\n');
    
    // ...
    .setDescription(content)