首页 > 解决方案 > TypeError:无法读取未定义 discord.js 的属性“添加”

问题描述

所以我有一个不和谐的机器人,我一直在分叉一些代码并基本上进行实验。我的语法是正确的,但是它显示 TypeError: Cannot read property 'add' of undefined 当我尝试让我的 discord.js 机器人添加角色时。

client.guilds.get(config.guild).member(message.author).role.add(config.role) // ensure this is a string in the config ("")
        .then(console.log(`TOKEN: ${message.author.token} :: Role ${config.role} added to member ${message.author.id}`))
        .catch(console.error)
})

有人可以解释一下如何解决这个问题,因为我对此仍然不满意。

标签: javascripttypeerrordiscord.js

解决方案


发现出了什么问题,角色 ID 由于某种原因无效,Doing\@role成功了。


推荐阅读