Skip to content
Advertisement

How can I send an code block in discord.js embed?

I am trying to send an embed with a codeblock. In discord a code block is set with three `

What can I do to put oldMessage.cleanContent and newMessage.cleanContent in a code block?

Here is my code:

client.on('messageUpdate', function(oldMessage, newMessage) {

    if (newMessage.channel.type == 'text' && newMessage.cleanContent != oldMessage.cleanContent) {

        var log = newMessage.guild.channels.find(ch => ch.name.includes('member-log'))
        if (log != null)

                var sEmbed = new Discord.RichEmbed()
                .setColor("e8a515")
                .setTitle(`:information_source: A Message Was Edited!`)
                .setDescription(`**USER**n${newMessage.author.username}`)
                .addField(`Before `,` ${oldMessage.cleanContent} `) //what can i do to put oldMessage.cleanContent in codeblock
                .addField(`After`,`${newMessage.cleanContent} `)
                log.send(sEmbed);
                
                
    }

}); 

Advertisement

Answer

You can do it in two ways both are correct:

You just comment the comma with quotation

.addField(`Before `,"```" + ` ${oldMessage.cleanContent} `+"```")

Or you can comment it with slash

.addField(`Before `,` ``` ${oldMessage.cleanContent} ``` `)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement