diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index a1586b0f05db..50bd0f195207 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -2,6 +2,7 @@ const BaseManager = require('./BaseManager'); const Role = require('../structures/Role'); +const Collection = require('../util/Collection'); const Permissions = require('../util/Permissions'); const { resolveColor } = require('../util/Util'); @@ -31,10 +32,10 @@ class RoleManager extends BaseManager { /** * Obtains one or more roles from Discord, or the role cache if they're already available. - * @param {Snowflake} [id] ID or IDs of the role(s) - * @param {boolean} [cache=true] Whether to cache the new roles objects if it weren't already + * @param {Snowflake} [id] ID of the role to fetch + * @param {boolean} [cache=true] Whether to cache the new role object(s) if they weren't already * @param {boolean} [force=false] Whether to skip the cache check and request the API - * @returns {Promise} + * @returns {Promise>} * @example * // Fetch all roles from the guild * message.guild.roles.fetch() @@ -53,9 +54,10 @@ class RoleManager extends BaseManager { } // We cannot fetch a single role, as of this commit's date, Discord API throws with 405 - const roles = await this.client.api.guilds(this.guild.id).roles.get(); - for (const role of roles) this.add(role, cache); - return id ? this.cache.get(id) || null : this; + const data = await this.client.api.guilds(this.guild.id).roles.get(); + const roles = new Collection(); + for (const role of data) roles.set(role.id, this.add(role, cache)); + return id ? roles.get(id) || null : roles; } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index fe4a07e7d85c..a54a3540f91b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2011,7 +2011,7 @@ declare module 'discord.js' { public create(options?: { data?: RoleData; reason?: string }): Promise; public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise; - public fetch(id?: Snowflake, cache?: boolean, force?: boolean): Promise; + public fetch(id?: Snowflake, cache?: boolean, force?: boolean): Promise>; } export class UserManager extends BaseManager {