【问题标题】:TypeError: Cannot read property 'add' of undefined discord.jsTypeError:无法读取未定义 discord.js 的属性“添加”
【发布时间】:2019-04-21 11:14:33
【问题描述】:

所以我有一个不和谐的机器人,我一直在分叉一些代码并基本上进行实验。我的语法是正确的,但是它显示 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)
})

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

【问题讨论】:

  • 使用member.addRole 而不是member.roles.add discord.js.org/#/docs/main/stable/class/…
  • 所以应该是 client.guilds.get(config.guild).member(message.author).addRole(config.role)?
  • 现在我得到 TypeError:提供的参数既不是角色也不是雪花。什么时候是角色?

标签: javascript typeerror discord.js


【解决方案1】:

找出问题所在,角色 ID 由于某种原因无效,执行\@role 成功了。

【讨论】:

    最近更新 更多