Discord.js TypeError: message.member.roles.find is not a function

佐手、 提交于 2020-08-26 16:24:13

问题


pls help

CODE case 'clear': if(!message.member.roles.find(r => r.name === "OWNER"))

OUTPUT

if(!message.member.roles.find(r => r.name === "OWNER"))
TypeError: message.member.roles.find is not a function

回答1:


GuildMember.roles returns an object of type GuildMemberRoleManager. To get the roles from this you want to use GuildMemberRoleManager.cache. This returns an object of type Collection<Snowflake, Role>. Once you have that, you can use Collection.find(fn, [thisArg]). BUT, in your specific case, you'd want to use Collection.some(fn, [thisArg]). The some method checks if a specific item exists based on a function.

Your code would instead look like this:

if(!message.member.roles.cache.some(r => r.name === "OWNER")) {
    //your code here
}


来源:https://stackoverflow.com/questions/60623190/discord-js-typeerror-message-member-roles-find-is-not-a-function

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