0

Basically if a user types more than 2048 characters in the description embed the embed would get split in 2 embeds and will send it in the guild. The part i dont understand how to fix, is splitting the embed in 2 messages. So first embed untill the end so 2048 then it will send another embed with the rest of the message.

You can see in the code below. If this ${test} contains more than 2048 then split that in 2 embeds

message.author.send(new Discord.RichEmbed().setColor("00FFFF").setDescription( **Here is what you typed:**  \n \n **Test:** \n ${test}))
  • Welcome to Stackoverflow. The problem looks like you need to split your message, did you try something? If so please provide the code of your attemp. Or is your problem not knowing how to split a string in chunks no more than 2048 characters? If that's the case then you should search for this first in stackoverflow and change your question title accordingly if you can't find any answer. – remix23 Apr 23 '19 at 20:43

1 Answers1

2

To split the string you can use the method provided in this answer: if you match the string with this RegExp /.{1,2048}/g you'll get an Array with all the substrings you need. You can use that array to build every embed.

Here's a function you can use to do that:

async function sendEmbeds(text, channel) {
  const arr = text.match(/.{1,2048}/g); // Build the array

  for (let chunk of arr) { // Loop through every element
    let embed = new Discord.RichEmbed()
      .setColor("00FFFF")
      .setDescription(chunk);

    await channel.send({ embed }); // Wait for the embed to be sent
  }
}

To implement it, simply call it providing the text and the channel. In you case:

sendEmbeds(` **Here is what you typed:**  \n \n **Test:** \n ${test})`, message.author)
Federico Grandi
  • 6,785
  • 5
  • 30
  • 50