我应该如何从id中获取角色对象?discord.js我正在使用
message.guild.roles.cache(toString(role id here))
它是cache.get
,因为cache
是Collection
的实例
参见<Collection>.get
message.guild.roles.cache.get(id)
在最新版本的discord.js中,<RoleManager>.cache
具有Collection 类型
因此,要获得存储在集合中的值,需要使用.get("key")
方法
示例:
const roleId = "your-role-id";
message.guild.roles.cache.get(roleId) // Returns <Role> object