javascript - 不和谐.js | TypeError:无法读取 null 的属性“禁令”
问题描述
目的:在创建频道时删除频道,然后禁止创建频道的成员。
代码 :
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.
有人可以帮我解决这个错误吗?
解决方案
推荐阅读
- generics - 通用数学运算符重载而不复制
- docker - 有没有办法将 USER 保留在 docker 基础映像上?
- c++ - 将一对映射到结构
- r - 如何在 r 中使用 VIF?
- excel - 在空白单元格下方的行中注入公式
- python - 在 Python 中根据时间序列数据分配组号
- laravel - 在 laravel 上更改 vuetify 主题
- javascript - 在数组对象中添加值
- cntk - 在训练 ONNX 的预训练模型 Emotion FerPlus 时抛出异常 'cuDNN failure 8: CUDNN_STATUS_EXECUTION_FAILED'
- javascript - ERR_NAME_NOT_RESOLVED - 上传错误时的 Firebase 存储