我最近在制作一个自动审核机器人。我确定如果该人有30条警告,该人将被禁止。但是它向我显示了一个错误。我尝试自己修复它,但不知道问题出在哪里。这是我使用的代码:
if (warns.warns.length === 30 && message.member.bannable) {
embed.addField(
`⛔ ${message.author.tag} has reached 30 warnings.`,
`**${message.author} has been banned permanently.**`,
true
);
setTimeout(function() {
message.member
.send(banemb)
.then((message) => message.member.ban({ reason: '30 warnings' }));
}, 1000);
}
这是我得到的错误:
{
"stack": "TypeError: Cannot read property 'ban' of null
at /app/app.js:157:51
at processTicksAndRejections (internal/process/task_queues.js:88:5)"
}
答案 0 :(得分:4)
将.then(message =>
更改为.then(msg =>
因为您覆盖了消息变量,所以新的message
变量为null
setTimeout(function() {
message.member
.send(banemb)
.then((msg) => message.member.ban({ reason: '30 warnings' }));
}, 1000);