[英]Discord.js RichEmbed field values “empty” even thought they are not. messageUpdate
所以基本上我一直在為消息編輯制作日志。 該功能的目的是在有人編輯消息時寫入 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}')
感謝您通讀整個問題,我將不勝感激任何幫助或提示解決此問題。
真誠的,-盧克
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)}\n\u200B`)
.addField(`New Message:` , `${newMessage.content.slice(0, 950)}\n\u200B`)
.addField(`In channel:` , oldMessage.channel.name)
.addField(`By` , oldMessage.author.tag)
.setTimestamp()
newMessage.channel.send(msgup).catch(console.error);
};
});
我相信是oldMessage
會導致這種情況。 這是我所做的,所以它不能為空。 ( oldMessage.author
.name
添加到您的message.channel
以便正確顯示名稱,與oldMessage.author
相同,我添加了.tag
)希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.