fix(RoleManager): fix ID return value, change return type to collection (#4935)

Co-authored-by: Ishmaam Khan <ishmaamk@gmail.com>
This commit is contained in:
Jan
2020-11-22 19:39:19 +01:00
committed by GitHub
parent 6f3076325e
commit 12a096b5f1
2 changed files with 9 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
const BaseManager = require('./BaseManager'); const BaseManager = require('./BaseManager');
const Role = require('../structures/Role'); const Role = require('../structures/Role');
const Collection = require('../util/Collection');
const Permissions = require('../util/Permissions'); const Permissions = require('../util/Permissions');
const { resolveColor } = require('../util/Util'); 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. * 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 {Snowflake} [id] ID of the role to fetch
* @param {boolean} [cache=true] Whether to cache the new roles objects if it weren't already * @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 * @param {boolean} [force=false] Whether to skip the cache check and request the API
* @returns {Promise<Role|RoleManager>} * @returns {Promise<?Role|Collection<Snowflake, Role>>}
* @example * @example
* // Fetch all roles from the guild * // Fetch all roles from the guild
* message.guild.roles.fetch() * 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 // 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(); const data = await this.client.api.guilds(this.guild.id).roles.get();
for (const role of roles) this.add(role, cache); const roles = new Collection();
return id ? this.cache.get(id) || null : this; for (const role of data) roles.set(role.id, this.add(role, cache));
return id ? roles.get(id) || null : roles;
} }
/** /**

2
typings/index.d.ts vendored
View File

@@ -2011,7 +2011,7 @@ declare module 'discord.js' {
public create(options?: { data?: RoleData; reason?: string }): Promise<Role>; public create(options?: { data?: RoleData; reason?: string }): Promise<Role>;
public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<Role | null>; public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<Role | null>;
public fetch(id?: Snowflake, cache?: boolean, force?: boolean): Promise<this>; public fetch(id?: Snowflake, cache?: boolean, force?: boolean): Promise<Collection<Snowflake, Role>>;
} }
export class UserManager extends BaseManager<Snowflake, User, UserResolvable> { export class UserManager extends BaseManager<Snowflake, User, UserResolvable> {