pls帮助
代码案例清除: if(!message.member.roles.find(r => r。名称===所有者))
CODE case 'clear': if(!message.member.roles.find(r => r.name === "OWNER"))
输出
if(!message.member.roles.find(r => r.name === "OWNER")) TypeError: message.member.roles.find is not a function推荐答案
GuildMember.roles 返回一个对象 GuildMemberRoleManager 类型的。要从中获取角色,您想使用 GuildMemberRoleManager.cache 。这将返回类型为 Collection<雪花,角色> 的对象。一旦有了它,就可以使用 Collection.find(fn,[thisArg])。但是,在您的特定情况下,您想使用 Collection.some(fn,[thisArg])。 some 方法根据功能检查是否存在特定项目。
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 }更多推荐
Discord.js TypeError:message.member.roles.find不是函数
发布评论