简体   繁体   中英

Discord.js Embed Issues

Trying to send embed crashes and logs out with error:

"RangeError: RichEmbed field values may not be empty."

I've tried adding multiple checks to see if anything is not unidentified and is causing the issue, but nothing seems to fix it.

The embed is fully sent, but in the end it breaks and crashes the bot.

    client.on("messageUpdate",(oldMsg,newMsg) =>{
    if(newMsg.author.bot && !newMsg.guild){return}
    //console.log(oldMsg.content,newMsg.content)
    messageEditEmbed(oldMsg,newMsg);
})



function messageEditEmbed(o,n){
    let channel = o.guild.channels.find(channel => channel.name === "logs");

    if(channel){
        let embed = new discord.RichEmbed()
        .setDescription(`***A message was edited by ${o.author} in ${o.channel}*** `)
        if(o){embed.addField("Before: ",o.content)}
        if(n){embed.addField("After: ",n.content)}
        channel.send(embed);
    }
}

It should just turn smoothly as it does, but not crash...

你还记得const Discord = require('discord.js')吗?

The issue is most likely that o.content or n.content is empty. This is natural when an message is changed and contents is removed/added.

One way to handle this, is not trying to add the field if the actual content is empty, and another way is to add a zero-width space in front of the potentially empty field, for example to do \​${n.content} .

Do note that o and n can exist and be non-empty, whilst o.content and n.content still are empty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM