[英]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).我正在尝试在 Discord 中使用用户输入嵌入并显示它(来自斜杠命令)。 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.具体来说,当我使用
.setDescription(content)
设置嵌入的“内容”时,文本以一种没有吸引力的格式出现。
I have tried using the \n
character to create new lines, but it is not working.我曾尝试使用
\n
字符来创建新行,但它不起作用。 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"
.如果您使用
interaction.options.getString("content")
接收content
,则\n
不再是换行符,更像是转义的反斜杠"\\"
后跟字母"n"
。
It means you can replace those with a newline character:这意味着您可以用换行符替换它们:
let content = interaction.options
.getString('content')
.replaceAll('\\n', '\n');
// ...
.setDescription(content)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.