Reputation: 25
So I have a section of code which is designed to send an embed to a logging channel with the old and new message whenever a message is updated. However, whenever I test the code, the embed is sent successfully, but an error RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values may not be empty
occurs, and the bot crashes. I can find no reason why this error would occur, because all the fields return the values I specified.
The only thing I noticed that was strange is when I added the code to the bot, all embeds started to encounter the same error, but when I commented out the code, the embeds returned to normal.
Does anyone know why this error would occur? If so, how would I fix it?
This is the code:
var channel = newMessage.guild.channels.cache.find(ch => ch.name === 'bot-log');
var log = new MessageEmbed()
.setAuthor(oldMessage.author.tag, oldMessage.author.displayAvatarURL())
.setDescription(`:pencil: **[Message](${newMessage.url}) by ${newMessage.author} was edited in <#${oldMessage.channel.id}>**`)
.setColor(0x686afd)
.addFields(
{ name: `Old message`, value: oldMessage.content},
{ name: `New message`, value: newMessage.content},
)
.setTimestamp()
.setFooter(`Message ID: ${newMessage.id}`);
return channel.send(log);
});
Upvotes: 0
Views: 306
Reputation: 11
I Think This Code Is The Right One :v
var channel = message.channel;
var log = new MessageEmbed()
.setAuthor(message.author.tag, message.author.displayAvatarURL())
.setDescription(`:pencil: **[Message](${message.url}) by ${message.author.tag} was edited in <#${message.channel.id}>**`)
.setColor(0x686afd)
.addFields(
{ name: `Old message`, value: message.content},
{ name: `New message`, value: message.content},
)
.setTimestamp()
.setFooter(`Message ID: ${message.id}`);
return channel.send(log);
Upvotes: 0
Reputation: 2722
Its happens because message content can be empty, like if user attach some files without text. You can check newMessage.content.length and oldMessage.content.length, and change it to what ever you want.
Like:
newMessage.content = newMessage.content.length > 0 ? newMessage.content : 'empty message'
oldMessage.content = oldMessage.content.length > 0 ? oldMessage.content : 'empty message'
Upvotes: 1