Discord.js TypeError:message.member.roles.find不是函数 [英] Discord.js TypeError: message.member.roles.find is not a function

查看:64
本文介绍了Discord.js TypeError:message.member.roles.find不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆