Allowsik
Allowsik

Reputation: 3

discord.js \n doesn't break line in embed description

const channel = options.getChannel("channel");
const title = options.getString("title");
const msg = options.getString("description");

const ancEmbed = new MessageEmbed()
  .setColor('DARK_VIVID_PINK')
  .setTitle(title)
  .setDescription(msg)
       
channel.send({embeds: [ancEmbed]});

What might be wrong with this? \n don't get replaced into new lines.. Discord Embed Image

Upvotes: 0

Views: 1145

Answers (1)

isaac.g
isaac.g

Reputation: 726

It's because you're setting the description to the content of the user's command, and if the user inputs a \n, Discord automatically escapes it so that your interaction receives it as the text \n, not the newline \n. Here's a replace function using a regex that replaces all the text \n with an actual newline \n character of the content of the message:

var msg = options.getString("description");
msg = msg.replace(/\\n/g, "\n");

Upvotes: 1

Related Questions