简体   繁体   中英

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?

外观如何

I get the content directly from the user input:

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM