For one of my Discord bots, I need an array that contains all the roles a person has. Is there any way to do this? I am using discord.js
From the official docs on GuildMember
:
.roles
A manager for the roles belonging to this member.Type:
GuildMemberRoleManager
Looking at GuildMemberRoleManager
, we see a very interesting property:
.cache
The roles of this member.Type:
Collection <Snowflake, Role >
However, we don't want a Collection
, we want an array, so we can reference the docs for collection , which reveals an array
method that returns an array of the values. So, the final code is:
const roles = member.roles.cache.array();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.