Search code examples
node.jsembeddiscord.js

discord.js reduce message.content to 1024 char


how can i reduce message.content to below 1024 char my code is like this in messageDelete event is

module.exports = async (client, channel ) => {
    var log = channel.guild.channels.find(ch => ch.name.includes('member-log')) ;
 var sEmbed = new Discord.RichEmbed()
                .setColor("RANDOM")
                .setTitle(`:warning: A Message Was Deleted!`)
                .setDescription(`**USER**\n<@${message.author.id}>`)
                .addField(`**Content**`,` \`\`\`${message.content}\`\`\` `)
                .addField(`**Channel**`,`<#${message.channel.id}> (${message.channel.id})`)
                .setFooter(``)
                .setFooter(`MessageID:${message.author.lastMessageID} | AuthorID:${message.author.id}`);
                log.send(sEmbed);

error RichEmbed() cannot send more than 1024 char


Solution

  • This should do it

    var msg;
    // if the message length is more than 1023 characters
    if (message.content.length >= 1023) {
        // split the content into an array
        msg = message.content.split(); // ['more than 1023 characters'] 
    } else {
        // else just assign the content to the msg variable
        msg = message.content;
    }
    console.log(msg || msg[0])