javascript - 无法读取 null 的属性“角色”。在加入服务器后向用户添加角色时
问题描述
所以基本上我只需要它来添加角色并且机器人具有权限并且角色就在那里。完整的控制台如下
(c) 2020 Microsoft Corporation. All rights reserved.
C:\Users\thato\Desktop\Deku>node .
sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules\sequelize\lib\sequelize.js:245:13
═[Discord-Leveling Database Loaded -V1.1.0]═[Support server: https://discord.gg/eBFKDbx]=
Loading...
D3ku is online!
New member joined server, successfully sent a message!
New member joined server, successfully sent a message!
C:\Users\thato\Desktop\Deku\index.js:358
let DaRole = message.guild.roles.cache.find(r => r.name === 'Human')
^
TypeError: Cannot read property 'roles' of null
at Client.<anonymous> (C:\Users\thato\Desktop\Deku\index.js:358:32)
at Client.emit (events.js:326:22)
at MessageCreateAction.handle (C:\Users\thato\Desktop\Deku\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\thato\Desktop\Deku\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
(HERE WAS A BUNCH OF RANDOM ERRORS NO ONE NEEDS)
C:\Users\thato\Desktop\Deku>```
I really can\'t get it to send immediately either. It only sends the welcome message when the user sends a message in the server. That\'s also when the error finally appears.
解决方案
错误说明message.guild
是null
. 这可能发生在部分消息或来自 DM 的消息上。
message.partial
如果消息是部分消息,则为true
. 要获取消息的其余部分,请运行message.fetch().then(fullmessage => {...})
.
message.channel.type === 'dm'
可以告诉您消息是否来自 DM。
推荐阅读
- identityserver4 - 如何在 foxx 框架中验证 Oauth 访问令牌
- terraform - 如何避免 terraform vpc 模块为每个子网创建路由表?
- out-of-memory - Netty:为什么preferDirectBufs模式的moory使用量大于设置为false?
- javascript - 如何为调查保存号码?
- spring-boot - mapstruct 映射 id 到嵌套对象对象 Sring boot
- python - 如何为 pyttsx3 python 添加自己的 tts 声音
- android - kotlin.Unit 不能转换为 java.util.List。用于 getFilter 上的自定义适配器
- blockchain - 您如何为您的运行时编写系统测试?
- google-bigquery - 在 BigQuery 上使用以下查询时出现 TIMESTAMP 错误
- python - 为 anaconda 安装 cot-reports 模块