TypeError: Cannot read properties of null (reading 'permissions') discord.js V13
TypeError: Cannot read properties of null (reading 'permissions') discord.js V13
我尝试做一个反 link bot discord,只有拥有 VIEW_AUDIT_LOG
权限的人才能发送 link 这是我的代码:
client.on("messageCreate", message => {
const { member } = message;
let blacklisted = ['http://', 'www.', 'https://'];
let foundInText = false;
if(!member.permissions.has(Permissions.FLAGS.VIEW_AUDIT_LOG)) {
for (var i in blacklisted) {
if (message.content.toLowerCase().includes(blacklisted[i].toLowerCase())) foundInText = true;
}
if (foundInText) {
const logembed = new MessageEmbed()
.setColor("DARK_AQUA")
.addField(' with message :', ` ${message.content} `, true)
if(!message.member.roles.cache.has("929434049011941386")) {
message.guild.channels.cache.get('941704496185221221').send({ content: `<@${message.author.id}> tried to send links in <#${message.channel.id}>`, embeds: [logembed] });;
message.delete();
message.channel.send("No links here, " + `${message.author}`);
}
}
}
});
但是当他删除带有 link 的消息时出现此错误:
if(!member.permissions.has(Permissions.FLAGS.VIEW_AUDIT_LOG)) {
^
TypeError: Cannot read properties of null (reading 'permissions')
好的,这是我的猜测....您两次或多次点击此事件处理程序...第一次是用户键入的消息。如果你console.log(message.member)
,你会得到他们的会员信息。第二次通过时,您将收到另一个事件,即您作为处理程序发送的消息。
所以简单的解决方案是在此事件处理程序的顶部或附近添加类似这样的内容:
if (message.author.bot) return;
这基本上是在测试调用您的活动的是否是机器人。确保您不 accepting/reacting 到其他机器人也是一种良好的卫生习惯,这可能会导致您可能不想要的垃圾邮件。
我尝试做一个反 link bot discord,只有拥有 VIEW_AUDIT_LOG
权限的人才能发送 link 这是我的代码:
client.on("messageCreate", message => {
const { member } = message;
let blacklisted = ['http://', 'www.', 'https://'];
let foundInText = false;
if(!member.permissions.has(Permissions.FLAGS.VIEW_AUDIT_LOG)) {
for (var i in blacklisted) {
if (message.content.toLowerCase().includes(blacklisted[i].toLowerCase())) foundInText = true;
}
if (foundInText) {
const logembed = new MessageEmbed()
.setColor("DARK_AQUA")
.addField(' with message :', ` ${message.content} `, true)
if(!message.member.roles.cache.has("929434049011941386")) {
message.guild.channels.cache.get('941704496185221221').send({ content: `<@${message.author.id}> tried to send links in <#${message.channel.id}>`, embeds: [logembed] });;
message.delete();
message.channel.send("No links here, " + `${message.author}`);
}
}
}
});
但是当他删除带有 link 的消息时出现此错误:
if(!member.permissions.has(Permissions.FLAGS.VIEW_AUDIT_LOG)) {
^
TypeError: Cannot read properties of null (reading 'permissions')
好的,这是我的猜测....您两次或多次点击此事件处理程序...第一次是用户键入的消息。如果你console.log(message.member)
,你会得到他们的会员信息。第二次通过时,您将收到另一个事件,即您作为处理程序发送的消息。
所以简单的解决方案是在此事件处理程序的顶部或附近添加类似这样的内容:
if (message.author.bot) return;
这基本上是在测试调用您的活动的是否是机器人。确保您不 accepting/reacting 到其他机器人也是一种良好的卫生习惯,这可能会导致您可能不想要的垃圾邮件。