TypeError: Cannot read properties of null (reading #39;status#39;) using slash commands(类型错误:无法使用劈开命令读取NULL的属性(正在读取状态)
本文介绍了类型错误:无法使用劈开命令读取NULL的属性(正在读取状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是discord.js V13,尝试使用成员在线状态检查其状态时收到以下错误:
错误:
TypeError: Cannot read properties of null (reading 'status')
at /home/runner/DinBot-Slash-CMDS/slashcmds/utilidad/serverinfo.js:59:76
at Map.filter (/home/runner/DinBot-Slash-CMDS/node_modules/discord.js/node_modules/@discordjs/collection/dist/index.js:1:2066)
at Object.run (/home/runner/DinBot-Slash-CMDS/slashcmds/utilidad/serverinfo.js:59:43)
at Client.<anonymous> (/home/runner/DinBot-Slash-CMDS/index.js:43:18)
at Client.emit (node:events:390:28)
at InteractionCreateAction.handle (/home/runner/DinBot-Slash-CMDS/node_modules/discord.js/src/client/actions/InteractionCreate.js:70:12)
at Object.module.exports [as INTERACTION_CREATE] (/home/runner/DinBot-Slash-CMDS/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/home/runner/DinBot-Slash-CMDS/node_modules/discord.js/src/client/websocket/WebSocketManager.js:350:31)
at WebSocketShard.onPacket (/home/runner/DinBot-Slash-CMDS/node_modules/discord.js/src/client/websocket/WebSocketShard.js:443:22)
at WebSocketShard.onMessage (/home/runner/DinBot-Slash-CMDS/node_modules/discord.js/src/client/websocket/WebSocketShard.js:300:10)*
编码:
const members = interaction.guild.members.cache;
.addField('Presencia',
`**Conectado:** ${members.filter(member => member.presence.status === 'online').size}
` +
`**Ausentes:** ${members.filter(member => member.presence.status === 'idle').size}
` +
`**No Molestar:** ${members.filter(member => member.presence.status === 'dnd').size}
` +
`**Desconectado:** ${members.filter(member => member.presence.status === 'offline').size}
` + 'u200b'
)
推荐答案
首先,确保启用了GUILD_PRESENCES
意图:https://stackoverflow.com/a/68528046/6126373
在V13中,presence
属性can now be null
,因此请确保还使用optional chaining operator或通过检查member.presence
是否为真来进行检查:
members.filter((member) => member.presence?.status === 'online').size;
// OR
members.filter((member) => member.presence && member.presence.status === 'online').size;
这篇关于类型错误:无法使用劈开命令读取NULL的属性(正在读取状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:类型错误:无法使用劈开命令读取NULL的属性(正在读取状态
基础教程推荐
猜你喜欢
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 动态更新多个选择框 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 我什么时候应该在导入时使用方括号 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01