[英]Discord.js Embed Issues
嘗試發送嵌入崩潰並以錯誤方式注銷:
“RangeError:RichEmbed 字段值不能為空。”
我嘗試添加多項檢查以查看是否有任何未識別的內容導致問題,但似乎沒有任何解決方法。
嵌入已完全發送,但最終它會中斷並使機器人崩潰。
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);
}
}
它應該像它一樣平穩轉動,但不會崩潰......
你還記得const Discord = require('discord.js')
嗎?
問題很可能是o.content
或n.content
為空。 當消息被更改並且內容被刪除/添加時,這是很自然的。
處理此問題的一種方法是,如果實際內容為空,則不嘗試添加字段,另一種方法是在可能為空的字段前添加零寬度空間,例如執行\${n.content}
.
請注意o
和n
可以存在並且非空,而o.content
和n.content
仍然是空的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.