Skip to content

Commit

Permalink
fix(RoleManager): fix ID return value, change return type to collecti…
Browse files Browse the repository at this point in the history
…on (#4935)

Co-authored-by: Ishmaam Khan <[email protected]>
  • Loading branch information
vaporoxx and Ishmaam Khan authored Nov 22, 2020
1 parent 6f30763 commit 12a096b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/managers/RoleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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<Role|RoleManager>}
* @returns {Promise<?Role|Collection<Snowflake, Role>>}
* @example
* // Fetch all roles from the guild
* message.guild.roles.fetch()
Expand All @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,7 @@ declare module 'discord.js' {

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<this>;
public fetch(id?: Snowflake, cache?: boolean, force?: boolean): Promise<Collection<Snowflake, Role>>;
}

export class UserManager extends BaseManager<Snowflake, User, UserResolvable> {
Expand Down

0 comments on commit 12a096b

Please sign in to comment.