Javascript 检查用户ID时出现不一致错误';在使用partials时也是如此。(Discord.js)
下面的代码是我用来跟踪已删除和编辑的邮件的代码。然而,当我试图检查用户ID(因为有时候,像groovy这样的不协调机器人会不断删除和编辑消息,我希望这些类型的用户绕过日志系统)并确保它是我想要的机器人的ID时,我得到了这个错误Javascript 检查用户ID时出现不一致错误';在使用partials时也是如此。(Discord.js),javascript,discord,discord.js,Javascript,Discord,Discord.js,下面的代码是我用来跟踪已删除和编辑的邮件的代码。然而,当我试图检查用户ID(因为有时候,像groovy这样的不协调机器人会不断删除和编辑消息,我希望这些类型的用户绕过日志系统)并确保它是我想要的机器人的ID时,我得到了这个错误 if (msg.author.id !== "760491381034319883" && msg.author.id !== "234395307759108106" && msg.author
if (msg.author.id !== "760491381034319883" && msg.author.id !== "234395307759108106" && msg.author.id !== "235088799074484224" && msg.author.id !== "252128902418268161") {
^ TypeError: Cannot read property 'id' of null
然而,错误是非常不一致的,有时发生,有时不发生,messageUpdate事件也是如此。另外,我还不能完全确定我是否正确使用了partials
bot.on('messageDelete', msg => {
if (msg.author.id !== "760491381034319883" && msg.author.id !== "234395307759108106" && msg.author.id !== "235088799074484224" && msg.author.id !== "252128902418268161") {
if (!msg.partial) {
const channel = bot.channels.cache.get('781032825050759229');
if (channel) {
const MessageDeletedByUser = new Discord.MessageEmbed()
.setColor('YELLOW')
.setThumbnail(msg.author.avatarURL(msg.author.defaultAvatarURL))
.addField(msg.author.tag + " (MESSAGE DELETED)", ":warning:** <@" + msg.author.id + ">" + "'s message was deleted by the user**\n ")
.addField("\n:speaking_head: Full Message :speaking_head:", "- `" + msg.content + "`")
.addField("\n\n:newspaper: Message Info :newspaper: ", "\n- Channel ID: " + msg.channel + ' [' + "<#" + msg.channel.id + ">" + "]" + "\n- User ID: " + msg.author.id + " [" + "<@" + msg.author.id + ">" + "]")
.setTimestamp()
.setFooter('--Depressed Children--');
channel.send(MessageDeletedByUser)
}
}
}});
bot.on('messageUpdate', (oldMessage, newMessage) => {
if (newMessage.channel.type !== 'dm') {
if (newMessage.author.id !== '760491381034319883' && newMessage.author.id !== '234395307759108106' && newMessage.author.id !== '235088799074484224' && newMessage.author.id !== '252128902418268161') {
if (!oldMessage.partial) {
const channel = bot.channels.cache.get('781032825050759229');
if (channel) {
const MessageEditedByUser = new Discord.MessageEmbed()
.setColor('BLURPLE')
.setThumbnail(newMessage.author.avatarURL(newMessage.author.defaultAvatarURL))
.addField(newMessage.author.tag + " (MESSAGE EDITED)", ":warning:** <@" + newMessage.author.id + ">" + "'s message was edited by the user**\n ")
.addField("\n:speaking_head: Old Message :speaking_head:", "- `" + oldMessage.content + "`")
.addField("\n:speaking_head: New Message :speaking_head:", "- `" + newMessage.content + "`")
.addField("\n\n:newspaper: Message Info :newspaper: ",
"\n- Channel ID: " + newMessage.channel + ' [' + "<#" + newMessage.channel.id + ">" + "]" +
"\n- User ID: " + newMessage.author.id + " [" + "<@" + newMessage.author.id + ">" + "]" +
"\n- Message ID: " + newMessage.id + ' [' + newMessage.url + '] ')
.setTimestamp()
.setFooter('--Depressed Children--');
channel.send(MessageEditedByUser)
}
}
}
}
}
bot.on('messageDelete',msg=>{
如果(msg.author.id!=“760491381034319883”和&msg.author.id!=“234395307759108106”和&msg.author.id!=“235088799074484224”和&msg.author.id!=“252128902418268161”){
如果(!msg.partial){
const channel=bot.channels.cache.get('781032825050759229');
中频(信道){
const MessageDeletedByUser=new Discord.MessageEmbed()
.setColor(“黄色”)
.set缩略图(msg.author.avatarURL(msg.author.defaultAvatarURL))
.addField(msg.author.tag+“(消息已删除)”,“:警告:**”+“”的消息已被用户删除**\n”)
.addField(“\n:speaking\u head:完整消息:speaking\u head:”,“-`”+msg.content+“`”)
.addField(“\n\n:paper:Message Info:paper:”,“\n-频道ID:“+msg.Channel+”[“+”+”]”+”\n-用户ID:“+msg.author.ID+”[“+”+”]))
.setTimestamp()文件
.setFooter('--抑郁儿童--');
channel.send(MessageDeletedByUser)
}
}
}});
bot.on('messageUpdate',(旧消息,新消息)=>{
如果(newMessage.channel.type!=“dm”){
如果(newMessage.author.id!='760491381034319883'和&newMessage.author.id!='234395307759108106'和&newMessage.author.id!='235088799074484224'和&newMessage.author.id!='252128902418268161'){
如果(!oldMessage.partial){
const channel=bot.channels.cache.get('781032825050759229');
中频(信道){
const MessageEditedByUser=new Discord.MessageEmbed()
.setColor('BLURPLE')
.set缩略图(newMessage.author.avatarURL(newMessage.author.defaultAvatarURL))
.addField(newMessage.author.tag+“(消息已编辑)”,“:警告:*“+”的消息已由用户编辑**\n”)
.addField(“\n:speaking\u head:Old Message:speaking\u head:”,“-`”+oldMessage.content+“`”)
.addField(“\n:speaking\u head:newMessage:speaking\u head:”,“-`”+newMessage.content+“`”)
.addField(“\n\n:报纸:消息信息:报纸:”,
\n-频道ID:“+newMessage.Channel+'['+'+'++']”+
\n-用户ID:“+newMessage.author.ID+”[“+”“+”]”+
“\n-消息ID:”+newMessage.ID+'['+newMessage.url+']')
.setTimestamp()文件
.setFooter('--抑郁儿童--');
channel.send(MessageEditedByUser)
}
}
}
}
}
))
如果有人能让我知道问题是什么以及如何解决它,我将不胜感激 您正在检查
消息。请在检查部分内容之前编写。如前所述,部分消息只能保证具有ID。在尝试访问分部之前,请始终检查分部中是否存在某些内容
希望这有帮助。这似乎奏效了。如何解决以前的消息(启动前未被bot缓存)在删除/编辑时未被记录的问题?我正在使用partials,但我不确定是否正确。