简体   繁体   English

Discord.js 嵌入问题

[英]Discord.js Embed Issues

Trying to send embed crashes and logs out with error:尝试发送嵌入崩溃并以错误方式注销:

"RangeError: RichEmbed field values may not be empty." “RangeError:RichEmbed 字段值不能为空。”

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.问题很可能是o.contentn.content为空。 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} .处理此问题的一种方法是,如果实际内容为空,则不尝试添加字段,另一种方法是在可能为空的字段前添加零宽度空间,例如执行\​${n.content} .

Do note that o and n can exist and be non-empty, whilst o.content and n.content still are empty.请注意on可以存在并且非空,而o.contentn.content仍然是空的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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