From 5a4219ae0d5352c2ee5e094ec80087f33db717eb Mon Sep 17 00:00:00 2001 From: Vaporox Date: Sat, 24 Oct 2020 15:43:05 +0200 Subject: [PATCH 1/4] fix(RoleManager): fix ID return value, change return type to collection --- src/managers/RoleManager.js | 8 +++++--- typings/index.d.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index a1586b0f05db..7a443e183097 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'); @@ -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 041039f9c884..8573c265cce3 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2027,7 +2027,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 { From 85cb114e8dbfa8c7754aabe7036c3ed359def660 Mon Sep 17 00:00:00 2001 From: Jan <66554238+Vaporox@users.noreply.github.com> Date: Sat, 24 Oct 2020 18:35:05 +0200 Subject: [PATCH 2/4] docs: update return type --- src/managers/RoleManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index 7a443e183097..66d55e1e7730 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -35,7 +35,7 @@ class RoleManager extends BaseManager { * @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 {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() From 17f0685b2a350a4e27fbadb82cb634e3b82b8bd5 Mon Sep 17 00:00:00 2001 From: Jan <66554238+Vaporox@users.noreply.github.com> Date: Sun, 8 Nov 2020 11:23:55 +0100 Subject: [PATCH 3/4] Update src/managers/RoleManager.js Co-authored-by: Ishmaam Khan --- src/managers/RoleManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index 66d55e1e7730..2c783185d197 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -35,7 +35,7 @@ class RoleManager extends BaseManager { * @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 {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() From 677260361ca0cf2b01345b9199de300547a289c7 Mon Sep 17 00:00:00 2001 From: Jan <66554238+Vaporox@users.noreply.github.com> Date: Fri, 20 Nov 2020 21:29:02 +0100 Subject: [PATCH 4/4] docs: you cannot pass multiple ids --- src/managers/RoleManager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/RoleManager.js b/src/managers/RoleManager.js index 2c783185d197..50bd0f195207 100644 --- a/src/managers/RoleManager.js +++ b/src/managers/RoleManager.js @@ -32,8 +32,8 @@ 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>} * @example