joey dibbs
joey dibbs

Reputation: 131

How to align text in a multiline Discord embed?

I have an embed with a long string that breaks the line. Since I am numbering each line the alignment is off. How can I correct this? I used \n to break the line for example purposes

This is currently how the embed looks

enter image description here

I would like to indent the second line to make the text look like:

  1. this is a long

    string

My Code:

command(client, 'title' , (message) => {

 const embed = new Discord.MessageEmbed()

    .setTitle('Title')
    .setColor('#C69B6D')
    .addFields(
       {
       name: 'Field' ,
       value: "1: this is a long \n string",
       inline: true,
       },
    )
 
 message.channel.send(embed).then(msg => {})
 
})

Upvotes: 0

Views: 8727

Answers (2)

joey dibbs
joey dibbs

Reputation: 131

So I found a somewhat "fix". If I use a code block; I can then use a string literal and force the line break where the string becomes too long then add spaces.

My embed now looks like

enter image description here

My Updated Code:

command(client, 'title' , (message) => {

 const embed = new Discord.MessageEmbed()

    .setTitle('Title')
    .setColor('#C69B6D')
    .addFields(
       {
       name: 'Field' ,
       value: "```1: this is a long \n   string```",
       inline: true,
       },
    )
 
 message.channel.send(embed).then(msg => {})
 
})

Upvotes: 1

Joe Moore
Joe Moore

Reputation: 2023

What you are trying to do is formally not supported without 'cheating' with spaces. I dont know if the string is of custom length, but if it is a constant string, just add in spaces where necessary:

const embed = new Discord.MessageEmbed()
    .setTitle('Title')
    .setColor('#C69B6D')
    .addFields(
    {
       name: 'Field' ,
       value: "1: this is a long \n    string", //adding 4 spaces will indent your string
       inline: true,
    },
);

I'm thinking of a way you could achieve this with a function that iterates through your string adding spaces where necessary but for what it is, it seems like unnecessary hassle

Upvotes: 1

Related Questions