【发布时间】:2021-04-28 23:27:19
【问题描述】:
目的:在频道创建时删除频道,然后禁止创建频道的成员。
代码:
bot.on('channelCreate', async (channel, member) => {
if (!channel.guild)
return;
const audit = (await channel.guild.fetchAuditLogs()).entries.first();
if (audit.action === 'CHANNEL_CREATE')
if (audit.executor.id === '833382653779509288')
return;
channel.delete();
channel.guild.member(executor).ban({reason: 'aaaaaa'})
})`
结果:频道被删除但用户未被封禁。
这是错误:
(node:8388) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'ban' of null
at Client.<anonymous> (C:\Users\Utilisateur\Desktop\discordbot4\main.js:30:49)
at processTicksAndRejections (internal/process/task_queues.js:82:5)
(node:8388) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by
rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8388) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
有人可以帮我解决这个错误吗?
【问题讨论】:
-
您的
channel.guild.member(executor)中executor的范围是什么?之前您使用过audit.executor。你有一些公共变量executor,它代表用户对象吗? -
audit.executor.id 用于指定 id 被反通道保护忽略。我想我应该在 channel.guild.member(executor) 中使用 audit.executor.id。 (我对 js 很陌生,刚脱离 lua)
标签: javascript discord discord.js