Discord.js TypeError:message.member.roles.find不是函数

编程入门 行业动态 更新时间:2024-10-21 06:02:57
本文介绍了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不是函数

本文发布于:2023-10-30 04:18:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541741.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   TypeError   js   Discord   message

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!