【问题标题】:How should I get a role object from id?我应该如何从 id 获取角色对象?
【发布时间】:2022-01-25 08:28:21
【问题描述】:

我应该如何从 id 获取角色对象? 不和谐.js 我正在使用

message.guild.roles.cache(toString(role id here))

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    它是cache.get,因为cacheCollection 的一个实例

    <Collection>.get

    message.guild.roles.cache.get(id)
    

    【讨论】:

      【解决方案2】:

      在最新版本的 discord.js 中,<RoleManager>.cache 的类型为 Collection

      因此,要获取存储在集合中的值,您需要使用 .get("key") 方法

      例子:

      const roleId = "your-role-id";
      message.guild.roles.cache.get(roleId) // Returns <Role> object
      

      【讨论】:

        猜你喜欢
        • 2019-08-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-11
        相关资源
        最近更新 更多