TypeError: Cannot read property 'add' of undefined discord.js

偶尔善良 提交于 2021-01-29 08:31:09

问题


So i have a discord bot, and i have been forking some code and basically experminting. my synax is right however it says TypeError: Cannot read property 'add' of undefined when i try to make my discord.js bot add a role.

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)
})

Could someone please explain how to fix this as i am still noobish at this.


回答1:


Found out what was wrong, the Role ID Was invalid for some reason, Doing \@role did the trick.



来源:https://stackoverflow.com/questions/53368797/typeerror-cannot-read-property-add-of-undefined-discord-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!