So basically I have been making an log for message edit. The aim of the function is to write in modlog channel if someone edits the message. Also I wanted bot to write message before and after update.
Here is the code:
bot.on('messageUpdate', (oldMessage, newMessage) => { var msgup = new Discord.RichEmbed() .setTitle(`**MESSAGE EDIT**`) .addField(`Old Message:` , `${oldMessage.content}`) .addField(`New Message:` , `${newMessage.content}`) .addField(`In channel:` , oldMessage.channel) .addField(`By` , oldMessage.author) .setTimestamp() newMessage.channel.send(msgup).catch(console.error); });
The console error :
C:Usersgrofgdesktopdiscordbotnode_modulesdiscord.jssrcstructuresRichEmbed.js:166 if (!/S/.test(value)) throw new RangeError('RichEmbed field values may not be empty.'); ^ RangeError: RichEmbed field values may not be empty. at RichEmbed.addField (C:Usersgrofgdesktopdiscordbotnode_modulesdiscord.jssrcstructuresRichEmbed.js:166:34) at Client.bot.on (C:Usersgrofgdesktopdiscordbotindex.js:455:6) at Client.emit (events.js:198:13) at MessageUpdateAction.handle (C:Usersgrofgdesktopdiscordbotnode_modulesdiscord.jssrcclientactionsMessageUpdate.js:13:16) at MessageUpdateHandler.handle (C:Usersgrofgdesktopdiscordbotnode_modulesdiscord.jssrcclientwebsocketpacketshandlersMessageUpdate.js:7:34) at WebSocketPacketManager.handle (C:Usersgrofgdesktopdiscordbotnode_modulesdiscord.jssrcclientwebsocketpacketsWebSocketPacketManager.js:105:65) at WebSocketConnection.onPacket (C:Usersgrofgdesktopdiscordbotnode_modulesdiscord.jssrcclientwebsocketWebSocketConnection.js:333:35) at WebSocketConnection.onMessage (C:Usersgrofgdesktopdiscordbotnode_modulesdiscord.jssrcclientwebsocketWebSocketConnection.js:296:17) at WebSocket.onMessage (C:Usersgrofgdesktopdiscordbotnode_moduleswslibevent-target.js:120:16) at WebSocket.emit (events.js:198:13)
What the bot does:
-Bot executes the function exactly as planned. I have all components in embed (Title, 4xFields, and a timestamp). In all fields everything is written correctly (old message,new message, channel and author) But what happens?
-Even though bot does the function it stops with error. The bot crashes and it says Field is empty even though It writes everything and is not empty surely.
What have i tried?
Firstly, I tried removing content from both oldMessage.content
and newMessage.content
. It does the same thing anyways.
Secondly, I tried making it like .addField('Old Message:' , oldMessage)
without '${}'
.
Also I have tried doing the same thing but with .content
.
It still does the same thing, it does the job but makes an error and crash.
Because of console error:
at Client.bot.on (C:Usersgrofgdesktopdiscordbotindex.js:455:6)
I tought it was problem at that embed because line 455 is exactly line with .addField('Old Message:' , '${oldMessage.content}')
Thanks for reading through whole question and I would appreciate any kind of help or hint for solution of this problem.
Sincerely, -Luke
Advertisement
Answer
bot.on('messageUpdate', (oldMessage, newMessage) => { if (oldMessage.author.bot) return; if (oldMessage.content === newMessage.content) return; if(!oldMessage.partial) { var msgup = new Discord.RichEmbed() .setTitle(`**MESSAGE EDIT**`) .addField(`Old Message:` , `${oldMessage.content.slice(0, 950)}nu200B`) .addField(`New Message:` , `${newMessage.content.slice(0, 950)}nu200B`) .addField(`In channel:` , oldMessage.channel.name) .addField(`By` , oldMessage.author.tag) .setTimestamp() newMessage.channel.send(msgup).catch(console.error); }; });
I believe it is oldMessage
that would be causing this. Here is what I have done, so it can’t be empty. (Also added .name
to your message.channel
so it shows the name properly, same with oldMessage.author
, I added .tag
) Hopefully this helped.