【发布时间】:2020-02-23 06:39:58
【问题描述】:
所以基本上我一直在为消息编辑制作日志。该功能的目的是在有人编辑消息时写入 modlog 频道。我也想让机器人在更新前后写消息。
代码如下:
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);
});
控制台错误:
C:\Users\grofg\desktop\discordbot\node_modules\discord.js\src\structures\RichEmbed.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:\Users\grofg\desktop\discordbot\node_modules\discord.js\src\structures\RichEmbed.js:166:34)
at Client.bot.on (C:\Users\grofg\desktop\discordbot\index.js:455:6)
at Client.emit (events.js:198:13)
at MessageUpdateAction.handle (C:\Users\grofg\desktop\discordbot\node_modules\discord.js\src\client\actions\MessageUpdate.js:13:16)
at MessageUpdateHandler.handle (C:\Users\grofg\desktop\discordbot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageUpdate.js:7:34)
at WebSocketPacketManager.handle (C:\Users\grofg\desktop\discordbot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (C:\Users\grofg\desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\Users\grofg\desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\Users\grofg\desktop\discordbot\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:198:13)
机器人的作用:
-Bot 完全按照计划执行功能。我嵌入了所有组件(标题、4xFields 和时间戳)。在所有领域中,所有内容都正确写入(旧消息、新消息、频道和作者)但是会发生什么?
-即使 bot 执行该功能,它也会因错误而停止。机器人崩溃了,它说 Field 是空的,即使它写了所有东西并且肯定不是空的。
我尝试了什么?
首先,我尝试从oldMessage.content 和newMessage.content 中删除内容。无论如何,它做同样的事情。
其次,我尝试在没有'${}' 的情况下将其设为.addField('Old Message:' , oldMessage)。
我也尝试过使用.content 做同样的事情。
它仍然做同样的事情,它完成了这项工作,但会出错并崩溃。
由于控制台错误:
at Client.bot.on (C:\Users\grofg\desktop\discordbot\index.js:455:6)
我认为这是嵌入的问题,因为第 455 行与 .addField('Old Message:' , '${oldMessage.content}') 完全一致@
感谢您通读整个问题,对于解决此问题的任何帮助或提示,我将不胜感激。
真诚地, -卢克
【问题讨论】:
-
你确定
oldMessage.content不是空的吗?如果您将console.log(oldMessage)作为第一行,它会打印什么? -
我的意思是其中的内容肯定不是空的,因为我在编辑前得到了充满消息的字段,编辑后是一条消息。但它仍然崩溃。
标签: javascript node.js bots discord discord.js