Home > OS >  Using \n from user input to make new line
Using \n from user input to make new line

Time:09-12

I am making command in my bot to send embed with specified parameters (like: title, description...), and I want my bot to recognize \n in user input as new line function (not just "\n" text).

This is how command input looks like:

command input

And this is how command output looks like:

command output

How command output should look like:

line1

line2

CodePudding user response:

I think it will be safer for your application to just manually replace them in content. You can simply use String.prototype.replaceAll method:

const processedDescription = originalDescription.replaceAll("\\n", "\n");

Also, as additional note: it might be much comfortable to use Discord Modals for embeds instead of command arguments. You can checkout how to use them (if you're using discord.js) here.

  • Related